// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 5e5+5;
int n, v[maxn], ps[maxn];
bool mark[maxn];
int inc(int i) {
return (i+1)%n;
}
int dec(int i) {
return (i-1+n)%n;
}
int g(int i, int x) {
if (i+x < n) {
return ps[i+x]-ps[i];
}
int j = (i+x)%n;
return ps[n-1]-ps[i]+ps[j];
}
int p(int i, int x) {
i = (i-x-1+n*2)%n;
return g(i, x);
}
int f(int i, int j) {
int l1, l2;
if (i < j) l1 = j-i-1, l2 = n-2-(j-i-1);
else l1 = n-2-(i-j-1), l2 = i-j-1;
int res1 = v[i]+g(i, (l1+1)/2);
if (l1&1) res1 += p(i, l2/2);
else res1 += p(i, (l2+1)/2);
int res2 = v[i]+p(i, (l2+1)/2);
if (l2&1) res2 += g(i, l1/2);
else res2 += g(i, (l1+1)/2);
return max(res1, res2);
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> v[i];
ps[i] = v[i];
if (i) ps[i] += ps[i-1];
}
int ans = 0;
for (int i = 0; i < n; i++) {
int l = 1, r = n-1;
while (r - l > 10) {
int m1 = l+(r-l)/3, m2 = r-(r-l)/3;
if (f(i, (i+l)%n) <= f(i, (i+r)%n)) {
r = m2;
}
else l = m1;
}
int res = inf;
for (; l <= r; l++) smin(res, f(i, (i+l)%n));
smax(ans, res);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |