Files
python/GESP/Level6/202503T2_Prepare.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
673 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 4e5 + 10;
int n;
LL a[N], s[N];
LL ans = -1e18;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[n + i] = a[i];
}
for (int i = 1; i <= 2 * n; i++)
s[i] = s[i - 1] + a[i];
// 对于每个位置i,枚举它前面n个位置,找最小前缀和
for (int i = 1; i <= 2 * n; i++) {
LL minPrefix = s[i - 1]; // 初始化为i-1位置的前缀和
for (int j = max(0, i - n); j <= i - 2; j++)
minPrefix = min(minPrefix, s[j]);
ans = max(ans, s[i] - minPrefix);
}
printf("%lld\n", ans);
return 0;
}