This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
#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;
}