求助!玄学问题还是什么?
查看原帖
求助!玄学问题还是什么?
775490
JMCJimmyMaker楼主2024/1/23 21:01

这是我去年这时候写的

//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;
}

几乎一摸一样的代码 但是测试时出现了如下情况
去年的代码测试 今年刚写的

咋回事妮?

2024/1/23 21:01
加载中...