求调
查看原帖
求调
1251525
wisdom2010楼主2025/1/17 08:17
#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1e5 + 10;
long long a[maxn];
int x;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> x;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int sum = 0;
	for(int i = 0; i < n - 1; i++)
	{
		if(a[i] + a[i + 1] > x)
		{
			sum += a[i] + a[i + 1] - x;
			a[i + 1] -= a[i] + a[i + 1] - x;
		}
	}
	cout << sum;
	return 0;
}
2025/1/17 08:17
加载中...