//define and head file
#include <bits/stdc++.h> //万能头文件
using namespace std;
//variables and structions
int n, x, a[100005];
long long ans;
//functions
//main function(run)
int main() {
cin >> n >> x;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < n - 1; i++)
{
if (a[i] + a[i + 1] > x)
{
ans += a[i + 1] - x + a[i];
a[i + 1] = x - a[i];
}
}
cout << ans;
return 0;
}
//some define
#define MAXS 0x3f3f3f
#define MINS -0x3f3f3f
#define mm(a, b) memset(a, b, sizeof(a))
#define ll long long
#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#include <bits/stdc++.h> //Niubility Head File
using namespace std;
//variables and structions
ll n, x, a[100050], ans = 0;
//functions
//main function
signed main() {
scanf("%d %d", &n, &x);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
for (int i = 1; i < n; i++)
{
if (a[i] + a[i + 1] > x)
{
ans += (a[i + 1] - x + a[i]);
a[i + 1] = x - a[i];
}
}
printf("%d", ans);
return 0;
}
几乎一摸一样的代码
但是测试时出现了如下情况
去年的代码测试
今年刚写的
咋回事妮?