#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct segtree {
int n;
vector<ll> t;
segtree(int m) : n(m), t(m*4, 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);
for (int l = 0, r = (n+1) / 2 - 1; l < n; l++, r++) {
ll sum = accumulate(arr.begin() + l, arr.begin() + r + 1, 0ll);
s.upd(l, r, sum);
}
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 |
1 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 |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |