# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
187108 | 2020-01-12T12:51:36 Z | Akashi | Candies (JOI18_candies) | C++14 | 211 ms | 10356 KB |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int n; long long a[200005]; int Left[200005], Right[200005]; priority_queue <pair <long long, int> > pq; int main() { scanf("%d", &n); for(int i = 1; i <= n ; ++i){ scanf("%lld", &a[i]); Left[i] = i - 1; Right[i] = i + 1; pq.push({a[i], i}); } Right[n] = 0; long long Sol = 0; for(int i = 1; i <= (n + 1) / 2 ; ++i){ while(!pq.empty() && a[pq.top().second] != pq.top().first) pq.pop(); int pos = pq.top().second; pq.pop(); Sol += a[pos]; printf("%lld\n", Sol); int L = Left[pos], R = Right[pos]; Left[pos] = Left[L]; Right[pos] = Right[R]; Right[Left[L]] = pos; Left[Right[R]] = pos; if(L && R) a[pos] = max(a[L] + a[R] - a[pos], -INF); else a[pos] = -INF; a[L] = a[R] = -INF; pq.push({a[pos], pos}); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 504 KB | Output is correct |
4 | Correct | 4 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 504 KB | Output is correct |
7 | Correct | 3 ms | 504 KB | Output is correct |
8 | Correct | 3 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 380 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 14 ms | 504 KB | Output is correct |
12 | Correct | 4 ms | 504 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 504 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 1 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 504 KB | Output is correct |
19 | Correct | 3 ms | 504 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 504 KB | Output is correct |
4 | Correct | 4 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 504 KB | Output is correct |
7 | Correct | 3 ms | 504 KB | Output is correct |
8 | Correct | 3 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 380 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 14 ms | 504 KB | Output is correct |
12 | Correct | 4 ms | 504 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 504 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 1 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 504 KB | Output is correct |
19 | Correct | 3 ms | 504 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
21 | Correct | 155 ms | 10120 KB | Output is correct |
22 | Correct | 150 ms | 10076 KB | Output is correct |
23 | Correct | 157 ms | 10356 KB | Output is correct |
24 | Correct | 106 ms | 10080 KB | Output is correct |
25 | Correct | 107 ms | 10048 KB | Output is correct |
26 | Correct | 108 ms | 9936 KB | Output is correct |
27 | Correct | 124 ms | 10208 KB | Output is correct |
28 | Correct | 125 ms | 10228 KB | Output is correct |
29 | Correct | 132 ms | 10264 KB | Output is correct |
30 | Correct | 151 ms | 10332 KB | Output is correct |
31 | Correct | 166 ms | 10240 KB | Output is correct |
32 | Correct | 127 ms | 10080 KB | Output is correct |
33 | Correct | 211 ms | 10076 KB | Output is correct |
34 | Correct | 166 ms | 9948 KB | Output is correct |
35 | Correct | 138 ms | 10120 KB | Output is correct |
36 | Correct | 155 ms | 10216 KB | Output is correct |
37 | Correct | 154 ms | 10204 KB | Output is correct |
38 | Correct | 156 ms | 10240 KB | Output is correct |
39 | Correct | 111 ms | 9972 KB | Output is correct |
40 | Correct | 130 ms | 10140 KB | Output is correct |
41 | Correct | 125 ms | 10176 KB | Output is correct |
42 | Correct | 164 ms | 10204 KB | Output is correct |
43 | Correct | 143 ms | 10248 KB | Output is correct |
44 | Correct | 135 ms | 10260 KB | Output is correct |
45 | Correct | 128 ms | 10204 KB | Output is correct |
46 | Correct | 152 ms | 10296 KB | Output is correct |
47 | Correct | 149 ms | 10320 KB | Output is correct |
48 | Correct | 154 ms | 10076 KB | Output is correct |
49 | Correct | 138 ms | 10044 KB | Output is correct |
50 | Correct | 137 ms | 10048 KB | Output is correct |