# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98193 | 2019-02-21T12:10:13 Z | onjo0127 | Candies (JOI18_candies) | C++11 | 189 ms | 10488 KB |
#include <bits/stdc++.h> using namespace std; long long A[200009]; int L[200009], R[200009]; bool chk[200009]; int main() { int N; scanf("%d",&N); priority_queue<pair<long long, int> > pq; for(int i=1; i<=N; i++) { scanf("%d",&A[i]); pq.push({A[i], i}); L[i] = i-1; R[i] = i+1; } pq.push({-1LL * 1e18, 0}); R[0] = 1; A[0] = -1LL * 1e18; pq.push({-1LL * 1e18, N+1}); L[N+1] = N; A[N+1] = -1LL * 1e18; long long ans = 0; for(int i=1; i<=(N+1)/2; i++) { long long v; int id; while(1) { tie(v, id) = pq.top(); pq.pop(); if(!chk[id]) break; } ans += v; printf("%lld\n",ans); A[id] = A[L[id]] + A[R[id]] - A[id]; pq.push({A[id], id}); chk[L[id]] = chk[R[id]] = 1; L[id] = L[L[id]]; R[id] = R[R[id]]; R[L[id]] = id; L[R[id]] = id; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 3 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 512 KB | Output is correct |
15 | Correct | 3 ms | 512 KB | Output is correct |
16 | Correct | 4 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 384 KB | Output is correct |
20 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 3 ms | 384 KB | Output is correct |
6 | Correct | 3 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 3 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 4 ms | 384 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 3 ms | 384 KB | Output is correct |
13 | Correct | 4 ms | 384 KB | Output is correct |
14 | Correct | 4 ms | 512 KB | Output is correct |
15 | Correct | 3 ms | 512 KB | Output is correct |
16 | Correct | 4 ms | 384 KB | Output is correct |
17 | Correct | 3 ms | 384 KB | Output is correct |
18 | Correct | 4 ms | 384 KB | Output is correct |
19 | Correct | 4 ms | 384 KB | Output is correct |
20 | Correct | 3 ms | 384 KB | Output is correct |
21 | Correct | 153 ms | 10012 KB | Output is correct |
22 | Correct | 181 ms | 10484 KB | Output is correct |
23 | Correct | 156 ms | 10280 KB | Output is correct |
24 | Correct | 100 ms | 10208 KB | Output is correct |
25 | Correct | 144 ms | 10256 KB | Output is correct |
26 | Correct | 101 ms | 10116 KB | Output is correct |
27 | Correct | 188 ms | 10252 KB | Output is correct |
28 | Correct | 131 ms | 10476 KB | Output is correct |
29 | Correct | 151 ms | 10460 KB | Output is correct |
30 | Correct | 119 ms | 10332 KB | Output is correct |
31 | Correct | 125 ms | 10332 KB | Output is correct |
32 | Correct | 169 ms | 10332 KB | Output is correct |
33 | Correct | 138 ms | 10080 KB | Output is correct |
34 | Correct | 131 ms | 10076 KB | Output is correct |
35 | Correct | 162 ms | 10248 KB | Output is correct |
36 | Correct | 175 ms | 10332 KB | Output is correct |
37 | Correct | 185 ms | 10332 KB | Output is correct |
38 | Correct | 147 ms | 10332 KB | Output is correct |
39 | Correct | 156 ms | 10076 KB | Output is correct |
40 | Correct | 112 ms | 10184 KB | Output is correct |
41 | Correct | 118 ms | 10076 KB | Output is correct |
42 | Correct | 180 ms | 10460 KB | Output is correct |
43 | Correct | 138 ms | 10488 KB | Output is correct |
44 | Correct | 149 ms | 10336 KB | Output is correct |
45 | Correct | 135 ms | 10332 KB | Output is correct |
46 | Correct | 166 ms | 10412 KB | Output is correct |
47 | Correct | 137 ms | 10332 KB | Output is correct |
48 | Correct | 189 ms | 10076 KB | Output is correct |
49 | Correct | 168 ms | 10124 KB | Output is correct |
50 | Correct | 152 ms | 10204 KB | Output is correct |