// Basically we want Bytesar to start on the computer with
// the maximum of the minimums of semicircle sums that contain
// that computer, since the operator is able to force him to do that
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000050;
int a[N];
ll sum[N], p[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], a[i + n] = a[i];
for (int i = 1; i <= n * 2; i++) sum[i] = sum[i - 1] + a[i]; // Prefix sums
int sz = (n + 1) / 2;
// Sums of semicircles
for (int i = 1; i <= n; i++) p[i] = sum[i + sz - 1] - sum[i - 1];
for (int i = n + 1; i <= n * 2; i++) p[i] = p[i - n];
// Monotonic queue - Easily get min in range
deque<int> dq;
for (int i = n - sz + 2; i <= n; i++) {
while (dq.size() && p[dq.back()] >= p[i]) dq.pop_back();
dq.push_back(i);
}
ll ans = 0;
for (int i = n + 1; i <= 2 * n; i++) {
while (dq.size() && p[dq.back()] >= p[i]) dq.pop_back();
dq.push_back(i);
// Make sure we only consider semicircle sums that contain
// the current computer i
while (dq.front() < i - sz + 1) dq.pop_front();
ans = max(ans, p[dq.front()]);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
296 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
296 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
712 KB |
Output is correct |
23 |
Correct |
3 ms |
532 KB |
Output is correct |
24 |
Correct |
2 ms |
524 KB |
Output is correct |
25 |
Correct |
3 ms |
632 KB |
Output is correct |
26 |
Correct |
3 ms |
624 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
392 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
544 KB |
Output is correct |
31 |
Correct |
3 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
3 ms |
552 KB |
Output is correct |
4 |
Correct |
16 ms |
3892 KB |
Output is correct |
5 |
Correct |
34 ms |
9124 KB |
Output is correct |
6 |
Correct |
45 ms |
11220 KB |
Output is correct |
7 |
Correct |
54 ms |
13408 KB |
Output is correct |
8 |
Correct |
88 ms |
22132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
420 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
296 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
3 ms |
712 KB |
Output is correct |
23 |
Correct |
3 ms |
532 KB |
Output is correct |
24 |
Correct |
2 ms |
524 KB |
Output is correct |
25 |
Correct |
3 ms |
632 KB |
Output is correct |
26 |
Correct |
3 ms |
624 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
2 ms |
392 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
544 KB |
Output is correct |
31 |
Correct |
3 ms |
552 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
2 ms |
388 KB |
Output is correct |
34 |
Correct |
3 ms |
552 KB |
Output is correct |
35 |
Correct |
16 ms |
3892 KB |
Output is correct |
36 |
Correct |
34 ms |
9124 KB |
Output is correct |
37 |
Correct |
45 ms |
11220 KB |
Output is correct |
38 |
Correct |
54 ms |
13408 KB |
Output is correct |
39 |
Correct |
88 ms |
22132 KB |
Output is correct |
40 |
Correct |
4 ms |
888 KB |
Output is correct |
41 |
Correct |
5 ms |
1176 KB |
Output is correct |
42 |
Correct |
7 ms |
1700 KB |
Output is correct |
43 |
Correct |
36 ms |
9244 KB |
Output is correct |
44 |
Correct |
89 ms |
22120 KB |
Output is correct |
45 |
Correct |
18 ms |
4600 KB |
Output is correct |
46 |
Correct |
53 ms |
13432 KB |
Output is correct |
47 |
Correct |
86 ms |
22216 KB |
Output is correct |
48 |
Correct |
76 ms |
22336 KB |
Output is correct |
49 |
Correct |
73 ms |
22568 KB |
Output is correct |
50 |
Correct |
72 ms |
22460 KB |
Output is correct |