#include<iostream>
using namespace std;
long long a[100005], x, s;
int n;
int main()
{
cin >> n >> x;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i < n; i++)
{
if (a[i] + a[i - 1] > x)
if (x - a[i - 1] >= 0)
{
s += a[i] - (x - a[i - 1]);
a[i] = x - a[i - 1];
}
else
{
s += a[i] + a[i - 1] - x;
a[i] = 0;
a[i - i] = x;
}
}
cout << s;
return 0;
}
洛谷P3817 小A的糖果进阶解法
最新推荐文章于 2022-10-15 17:39:05 发布
944

被折叠的 条评论
为什么被折叠?



