^-^
2026-08-11 10:13:59
发布于:河北
2阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
//提高输入输出速度的
int n;
cin >> n;
ll s = 0; // 前缀和,滚动
ll mx = 0; // max(s[1]~s[i])前缀中的最大值即A1--AN-1之间的最大值
ll b = 0; // 上一分钟结束位置
ll ans = 0;//答案
for(int i = 1; i <= n; ++i)
{
ll a;
cin >> a;
s += a;
mx = max(mx, s);
// 第i分钟内部的最大坐标:b + max(s1...si)
ans = max(ans, b + mx);
b = b + s; // b[i]
}
cout << ans << endl;
return 0;
}
这里空空如也





有帮助,赞一个