20求调
查看原帖
20求调
1008234
byk_ALEX楼主2025/7/29 22:14

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, x;
	long long s = 0;
	int a[100001] = {0};
	cin >> n >> x;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++){
		if(a[i - 1] + a[i] > x){
			s += (a[i - 1] + a[i] - x);
			if(a[i - 1] >= a[i]){
				a[i - 1] -= (a[i - 1] + a[i] - x);
			}
			else{
				a[i] -= (a[i - 1] + a[i] - x);
			}
		}
	} 
	cout << s;
	return 0; 
}
2025/7/29 22:14
加载中...