#include <bits/stdc++.h>
using namespace std;
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 1050000
ii n, v[maxn], r[maxn], ps[maxn];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
cin >> n;
for(ii i = 1; i <= n; i++) {
cin >> v[i];
v[i+n] = v[i];
}
for(ii i = 1; i <= 2*n; i++) {
ps[i] = ps[i-1] + v[i];
r[i] = INFii;
}
ii ans = 0;
ii sz = (n+1)/2;
//cout << sz << endl;
if(n > 6e3) {
ii i = 1;
for(ii j = 0; j < sz; j++) {
if(i+j <= 2*n && i-sz+j >= 0) {
//cout << " " << j << " " << i-sz+j+1 << " " << i+j << " " << ps[i+j] - ps[i-sz+j] << endl;
r[i] = min(r[i],ps[i+j] - ps[i-sz+j]);
}
}
i = n+1;
for(ii j = 0; j < sz; j++) {
if(i+j <= 2*n && i-sz+j >= 0) {
//cout << " " << j << " " << i-sz+j+1 << " " << i+j << " " << ps[i+j] - ps[i-sz+j] << endl;
r[i] = min(r[i],ps[i+j] - ps[i-sz+j]);
}
}
cout << max(r[1],r[n+1]) << endl;
return 0;
}
for(ii i = 1; i <= 2*n; i++) {
//cout << i << endl;
for(ii j = 0; j < sz; j++) {
if(i+j <= 2*n && i-sz+j >= 0) {
//cout << " " << j << " " << i-sz+j+1 << " " << i+j << " " << ps[i+j] - ps[i-sz+j] << endl;
r[i] = min(r[i],ps[i+j] - ps[i-sz+j]);
}
}
}
for(ii i = 1; i <= n; i++) {
ans = max(ans, min(r[i],r[i+n]));
//cout << i << " " << min(r[i],r[i+n]) << endl;
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
4 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
30 ms |
332 KB |
Output is correct |
23 |
Correct |
77 ms |
332 KB |
Output is correct |
24 |
Correct |
29 ms |
332 KB |
Output is correct |
25 |
Correct |
78 ms |
344 KB |
Output is correct |
26 |
Correct |
80 ms |
428 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
78 ms |
432 KB |
Output is correct |
31 |
Correct |
75 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
77 ms |
332 KB |
Output is correct |
4 |
Incorrect |
7 ms |
2124 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
4 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
30 ms |
332 KB |
Output is correct |
23 |
Correct |
77 ms |
332 KB |
Output is correct |
24 |
Correct |
29 ms |
332 KB |
Output is correct |
25 |
Correct |
78 ms |
344 KB |
Output is correct |
26 |
Correct |
80 ms |
428 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
78 ms |
432 KB |
Output is correct |
31 |
Correct |
75 ms |
428 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
77 ms |
332 KB |
Output is correct |
35 |
Incorrect |
7 ms |
2124 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |