#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int nextPower2(int n) {
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
return 1+n;
}
struct segtree {
int n;
vector<ll> t;
segtree(int m) : n(nextPower2(m)), t(n*2, 1e18) {}
void upd(int l, int r, ll x, int v, int tl, int tr) {
if (l <= tl && tr <= r) {
t[v] = min(t[v], x);
return;
}
if (tr < l || r < tl) return;
int mid = (tl+tr) / 2;
upd(l, r, x, v*2, tl, mid);
upd(l, r, x, v*2+1, mid+1, tr);
}
void upd(int l, int r, ll x) {
upd(l, r, x, 1, 0, n-1);
}
ll query(int i) {
ll res = t[i+=n];
for (i /= 2; i >= 1; i /= 2)
res = min(res, t[i]);
return res;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> arr(n*2);
for (int i = 0; i < n; i++) {
cin >> arr[i];
arr[i+n] = arr[i];
}
segtree s(n*2);
ll sum = accumulate(arr.begin(), arr.begin() + (n+1) / 2, 0ll);
for (int l = 0, r = (n+1) / 2 - 1; l < n; l++, r++) {
s.upd(l, r, sum);
sum -= arr[l];
if (r < n*2-1)sum += arr[r+1];
}
ll res = 0;
for (int i = 0; i < n; i++)
res = max(res, min(s.query(i), s.query(i+n)));
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
596 KB |
Output is correct |
4 |
Correct |
28 ms |
4948 KB |
Output is correct |
5 |
Correct |
63 ms |
10228 KB |
Output is correct |
6 |
Correct |
91 ms |
11488 KB |
Output is correct |
7 |
Correct |
105 ms |
20448 KB |
Output is correct |
8 |
Correct |
175 ms |
22788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
640 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
2 ms |
596 KB |
Output is correct |
35 |
Correct |
28 ms |
4948 KB |
Output is correct |
36 |
Correct |
63 ms |
10228 KB |
Output is correct |
37 |
Correct |
91 ms |
11488 KB |
Output is correct |
38 |
Correct |
105 ms |
20448 KB |
Output is correct |
39 |
Correct |
175 ms |
22788 KB |
Output is correct |
40 |
Correct |
4 ms |
852 KB |
Output is correct |
41 |
Correct |
7 ms |
1492 KB |
Output is correct |
42 |
Correct |
10 ms |
1620 KB |
Output is correct |
43 |
Correct |
67 ms |
10844 KB |
Output is correct |
44 |
Correct |
174 ms |
22904 KB |
Output is correct |
45 |
Correct |
30 ms |
5460 KB |
Output is correct |
46 |
Correct |
103 ms |
20448 KB |
Output is correct |
47 |
Correct |
170 ms |
22916 KB |
Output is correct |
48 |
Correct |
174 ms |
23176 KB |
Output is correct |
49 |
Correct |
158 ms |
22236 KB |
Output is correct |
50 |
Correct |
163 ms |
22228 KB |
Output is correct |