社区讨论

求助!玄学问题还是什么?

P3817小A的糖果参与者 2已保存回复 8

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
8 条
当前快照
1 份
快照标识符
@lrqd9o4f
此快照首次捕获于
2024/01/23 21:02
2 年前
此快照最后确认于
2024/01/24 08:48
2 年前
查看原帖

这是我去年这时候写的

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

今年我自己写的

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

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

回复

8 条回复,欢迎继续交流。

正在加载回复...