'commit'
This commit is contained in:
30
GESP/Level6/202503T2_Prepare.cpp
Normal file
30
GESP/Level6/202503T2_Prepare.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user