跳到正文

题解

P9974

Expert_Dream约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年12月24日
收录
2026年5月4日
更新
2026年9月9日
篇幅
约 2 分钟
题目
P9974

版本

  1. v2当前
  2. v1

博客园。

首先我们知道,对于 a1a_1 每一次是最先吃糖果的。所以必然有两个情况:

  • 全部给他吃了。
  • 吃了一些。

首先情况一,我们可以直接特判掉。

剩下情况二,吃了一些没吃完代表:吃了自己的高度,相当于身高 ×2\times 2。于是我们只需要进行 log⁡109\log 10^9 次。然后后面直接 O(n)O(n) 暴力。时间复杂度 O(nlog⁡109)O(n \log 10^9)。

C++
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
#define int long long
int n,m;
int a[N],b[N];
void solve(){
	cin >> n >> m;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	for(int i = 1;i <= m;i++)
		cin >> b[i];


	for(int i = 1;i <= m;i++){
		if(b[i] <= a[1]){
			a[1]+=b[i];
			continue;
		}
		int tmp = 1;
		for(int j = 1;j <= n;j++)
			if(a[j] >= tmp && tmp <= b[i]){
				int t=a[j]+1;
				a[j] += min(a[j]-tmp+1,b[i]-tmp+1);
				tmp = t;
			}
	}

	for(int i = 1;i <= n;i++)
		cout<<a[i]<<endl;

}

signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}