import java.io.*;
import java.util.*;
class hac {
public static void main(String[] args) throws IOException {
hac obj = new hac();
obj.doStuff();
}
// first # is val, second is pos
void add(ArrayDeque<int[]> q, int[] n) {
while (!q.isEmpty() && q.peekFirst()[0] >= n[0]) {
q.pollFirst();
}
q.addFirst(n);
}
int[] nums;
int[] sums;
private void doStuff() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
nums = new int[Integer.parseInt(br.readLine())];
sums = new int[nums.length];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < nums.length; i++) {
nums[i] = Integer.parseInt(st.nextToken());
}
br.close();
int cap = nums.length/2;
if (nums.length%2==1) cap++;
int rsum = 0;
for (int i = 0; i < cap; i++) {
rsum += nums[i];
}
for (int i = 0; i < nums.length; i++) {
sums[i] = rsum;
rsum -= nums[i];
rsum += nums[(i+cap)%nums.length];
}
ArrayDeque<int[]> q = new ArrayDeque<>();
int max = 0;
for (int i = 0; i < cap; i++) {
add(q, new int[] {sums[i], i});
}
for (int i = 0; i < nums.length; i++) {
max = Math.max(max, q.peekLast()[0]);
//System.out.println(q.peekLast()[0]);
if (q.peekLast()[1] == i) q.pollLast();
add(q, new int[] {sums[(i+cap)%nums.length], (i+cap)});
}
System.out.println(max);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
8848 KB |
Output is correct |
2 |
Correct |
57 ms |
8300 KB |
Output is correct |
3 |
Correct |
55 ms |
8284 KB |
Output is correct |
4 |
Correct |
59 ms |
8488 KB |
Output is correct |
5 |
Correct |
66 ms |
8452 KB |
Output is correct |
6 |
Correct |
61 ms |
8284 KB |
Output is correct |
7 |
Correct |
59 ms |
8200 KB |
Output is correct |
8 |
Correct |
68 ms |
8324 KB |
Output is correct |
9 |
Correct |
63 ms |
8588 KB |
Output is correct |
10 |
Correct |
62 ms |
8300 KB |
Output is correct |
11 |
Correct |
60 ms |
8152 KB |
Output is correct |
12 |
Correct |
61 ms |
8360 KB |
Output is correct |
13 |
Correct |
55 ms |
8200 KB |
Output is correct |
14 |
Correct |
66 ms |
8220 KB |
Output is correct |
15 |
Correct |
56 ms |
8336 KB |
Output is correct |
16 |
Correct |
61 ms |
8080 KB |
Output is correct |
17 |
Correct |
58 ms |
8240 KB |
Output is correct |
18 |
Correct |
58 ms |
8416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
8848 KB |
Output is correct |
2 |
Correct |
57 ms |
8300 KB |
Output is correct |
3 |
Correct |
55 ms |
8284 KB |
Output is correct |
4 |
Correct |
59 ms |
8488 KB |
Output is correct |
5 |
Correct |
66 ms |
8452 KB |
Output is correct |
6 |
Correct |
61 ms |
8284 KB |
Output is correct |
7 |
Correct |
59 ms |
8200 KB |
Output is correct |
8 |
Correct |
68 ms |
8324 KB |
Output is correct |
9 |
Correct |
63 ms |
8588 KB |
Output is correct |
10 |
Correct |
62 ms |
8300 KB |
Output is correct |
11 |
Correct |
60 ms |
8152 KB |
Output is correct |
12 |
Correct |
61 ms |
8360 KB |
Output is correct |
13 |
Correct |
55 ms |
8200 KB |
Output is correct |
14 |
Correct |
66 ms |
8220 KB |
Output is correct |
15 |
Correct |
56 ms |
8336 KB |
Output is correct |
16 |
Correct |
61 ms |
8080 KB |
Output is correct |
17 |
Correct |
58 ms |
8240 KB |
Output is correct |
18 |
Correct |
58 ms |
8416 KB |
Output is correct |
19 |
Correct |
61 ms |
8112 KB |
Output is correct |
20 |
Correct |
67 ms |
8328 KB |
Output is correct |
21 |
Correct |
67 ms |
8456 KB |
Output is correct |
22 |
Correct |
110 ms |
9540 KB |
Output is correct |
23 |
Correct |
173 ms |
11852 KB |
Output is correct |
24 |
Correct |
101 ms |
9368 KB |
Output is correct |
25 |
Correct |
168 ms |
12068 KB |
Output is correct |
26 |
Correct |
169 ms |
12088 KB |
Output is correct |
27 |
Correct |
70 ms |
8124 KB |
Output is correct |
28 |
Correct |
56 ms |
8212 KB |
Output is correct |
29 |
Correct |
61 ms |
8320 KB |
Output is correct |
30 |
Correct |
154 ms |
11684 KB |
Output is correct |
31 |
Correct |
161 ms |
11444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
8188 KB |
Output is correct |
2 |
Correct |
60 ms |
8092 KB |
Output is correct |
3 |
Correct |
175 ms |
11920 KB |
Output is correct |
4 |
Correct |
261 ms |
15428 KB |
Output is correct |
5 |
Correct |
268 ms |
17560 KB |
Output is correct |
6 |
Correct |
298 ms |
20984 KB |
Output is correct |
7 |
Correct |
285 ms |
22548 KB |
Output is correct |
8 |
Correct |
327 ms |
30240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
8848 KB |
Output is correct |
2 |
Correct |
57 ms |
8300 KB |
Output is correct |
3 |
Correct |
55 ms |
8284 KB |
Output is correct |
4 |
Correct |
59 ms |
8488 KB |
Output is correct |
5 |
Correct |
66 ms |
8452 KB |
Output is correct |
6 |
Correct |
61 ms |
8284 KB |
Output is correct |
7 |
Correct |
59 ms |
8200 KB |
Output is correct |
8 |
Correct |
68 ms |
8324 KB |
Output is correct |
9 |
Correct |
63 ms |
8588 KB |
Output is correct |
10 |
Correct |
62 ms |
8300 KB |
Output is correct |
11 |
Correct |
60 ms |
8152 KB |
Output is correct |
12 |
Correct |
61 ms |
8360 KB |
Output is correct |
13 |
Correct |
55 ms |
8200 KB |
Output is correct |
14 |
Correct |
66 ms |
8220 KB |
Output is correct |
15 |
Correct |
56 ms |
8336 KB |
Output is correct |
16 |
Correct |
61 ms |
8080 KB |
Output is correct |
17 |
Correct |
58 ms |
8240 KB |
Output is correct |
18 |
Correct |
58 ms |
8416 KB |
Output is correct |
19 |
Correct |
61 ms |
8112 KB |
Output is correct |
20 |
Correct |
67 ms |
8328 KB |
Output is correct |
21 |
Correct |
67 ms |
8456 KB |
Output is correct |
22 |
Correct |
110 ms |
9540 KB |
Output is correct |
23 |
Correct |
173 ms |
11852 KB |
Output is correct |
24 |
Correct |
101 ms |
9368 KB |
Output is correct |
25 |
Correct |
168 ms |
12068 KB |
Output is correct |
26 |
Correct |
169 ms |
12088 KB |
Output is correct |
27 |
Correct |
70 ms |
8124 KB |
Output is correct |
28 |
Correct |
56 ms |
8212 KB |
Output is correct |
29 |
Correct |
61 ms |
8320 KB |
Output is correct |
30 |
Correct |
154 ms |
11684 KB |
Output is correct |
31 |
Correct |
161 ms |
11444 KB |
Output is correct |
32 |
Correct |
63 ms |
8188 KB |
Output is correct |
33 |
Correct |
60 ms |
8092 KB |
Output is correct |
34 |
Correct |
175 ms |
11920 KB |
Output is correct |
35 |
Correct |
261 ms |
15428 KB |
Output is correct |
36 |
Correct |
268 ms |
17560 KB |
Output is correct |
37 |
Correct |
298 ms |
20984 KB |
Output is correct |
38 |
Correct |
285 ms |
22548 KB |
Output is correct |
39 |
Correct |
327 ms |
30240 KB |
Output is correct |
40 |
Correct |
205 ms |
12648 KB |
Output is correct |
41 |
Correct |
245 ms |
13580 KB |
Output is correct |
42 |
Correct |
279 ms |
14172 KB |
Output is correct |
43 |
Correct |
286 ms |
17700 KB |
Output is correct |
44 |
Correct |
359 ms |
30176 KB |
Output is correct |
45 |
Correct |
262 ms |
15656 KB |
Output is correct |
46 |
Correct |
302 ms |
22128 KB |
Output is correct |
47 |
Correct |
319 ms |
30272 KB |
Output is correct |
48 |
Correct |
314 ms |
30800 KB |
Output is correct |
49 |
Correct |
357 ms |
31612 KB |
Output is correct |
50 |
Correct |
365 ms |
31556 KB |
Output is correct |