两个题解的输出结果不一致
查看原帖
两个题解的输出结果不一致
715342
pxlamda楼主2023/2/20 22:05
#include<iostream>
using namespace std;
long long ans = 0; //一定要开long long!!!
int n, x, a[100002];
int main() {
	cin >> n >> x; //输入
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i < n; i++) //模拟,正着遍历
		if (a[i] + a[i + 1] > x) {  //如果相邻两盒>x
			ans += a[i + 1] - x + a[i]; //就吃后面的
			a[i + 1] = x - a[i];
		}
	cout << ans; //输出
	return 0;
}
2023/2/20 22:05
加载中...