#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
struct SegTree {
int n;
vector<ll> tree, lazy;
SegTree(int _n) : n(_n), tree(4*_n+5, 1e18), lazy(4*_n+5, 1e18) {}
void push(int u, int tl, int tr) {
if(lazy[u] == 1e18) return ;
tree[u] = min(tree[u], lazy[u]);
if(tl != tr) {
lazy[2*u] = min(lazy[u], lazy[2*u+1]);
lazy[2*u+1] = min(lazy[u], lazy[2*u+1]);
}
lazy[u] = 1e18;
}
void update(int u, int tl, int tr, int l, int r, ll v) {
push(u, tl, tr);
if(tl > tr || l > tr || tl > r) return ;
if(l <= tl && tr <= r) {
lazy[u] = min(lazy[u], v);
push(u, tl, tr);
return ;
}
int tm = (tl + tr) / 2;
update(2*u, tl, tm, l, r, v);
update(2*u+1, tm+1, tr, l, r, v);
tree[u] = min(tree[2*u], tree[2*u+1]);
}
ll query(int u, int tl, int tr, int l, int r) {
if(tl > tr || l > tr || tl > r) return 1e18;
push(u, tl, tr);
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return min(query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r));
}
void update(int l, int r, ll v) { update(1, 0, n-1, l, r, v); }
ll query(int l, int r) { return query(1, 0, n-1, l, r); }
};
signed main() {
int n;
cin >> n;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
for(int i=1; i<=n; i++) v.push_back(v[i]);
vector<ll> pref(2*n+1);
for(int i=1; i<=2*n; i++) pref[i] = pref[i-1] + v[i];
SegTree tree(n+1);
int len = (n + 1) / 2;
for(int i=1; i<=n; i++) {
ll val = pref[i+len-1] - pref[i-1];
if(i+len-1 <= n) tree.update(i, i+len-1, val);
else {
tree.update(i, n, val);
tree.update(1, i+len-1-n, val);
}
}
ll ans = 0;
for(int i=1; i<=n; i++) ans = max(ans, tree.query(i, i));
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
860 KB |
Output is correct |
4 |
Correct |
61 ms |
7596 KB |
Output is correct |
5 |
Correct |
140 ms |
18408 KB |
Output is correct |
6 |
Correct |
186 ms |
22952 KB |
Output is correct |
7 |
Correct |
227 ms |
27584 KB |
Output is correct |
8 |
Correct |
374 ms |
45488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
3 ms |
860 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
3 ms |
860 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
860 KB |
Output is correct |
35 |
Correct |
61 ms |
7596 KB |
Output is correct |
36 |
Correct |
140 ms |
18408 KB |
Output is correct |
37 |
Correct |
186 ms |
22952 KB |
Output is correct |
38 |
Correct |
227 ms |
27584 KB |
Output is correct |
39 |
Correct |
374 ms |
45488 KB |
Output is correct |
40 |
Correct |
6 ms |
1368 KB |
Output is correct |
41 |
Correct |
13 ms |
2240 KB |
Output is correct |
42 |
Correct |
20 ms |
3296 KB |
Output is correct |
43 |
Correct |
144 ms |
18528 KB |
Output is correct |
44 |
Correct |
364 ms |
45488 KB |
Output is correct |
45 |
Correct |
70 ms |
9172 KB |
Output is correct |
46 |
Correct |
245 ms |
27560 KB |
Output is correct |
47 |
Correct |
381 ms |
45592 KB |
Output is correct |
48 |
Correct |
397 ms |
45992 KB |
Output is correct |
49 |
Correct |
371 ms |
45064 KB |
Output is correct |
50 |
Correct |
385 ms |
44972 KB |
Output is correct |