辣鸡水题,忘记开LLwa了一次,,,,
#include <bits/stdc++.h>
using namespace std;
#define ls st<<1
#define rs st<<1|1
#define LL long long
const int MAXN= (int) 1e6+10;
int arr[MAXN];
int main() {
ios::sync_with_stdio(false);
LL n, x;
cin >> n;
LL sum = 0, ans = 0;
for (int i = 0; i < n; ++i) {
cin >> x;
sum += x;
if(sum < 0) {
ans -= sum; sum = 0;
}
}
cout << ans << endl;
return 0;
}

本文分享了一段用于解决ACM竞赛中特定问题的C++代码。该代码通过累加输入值并在总和小于零时进行调整来计算最终答案。文章讨论了如何避免整数溢出并确保正确处理大量数据。
747

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



