# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47913 | 2018-05-08T14:59:15 Z | Just_Solve_The_Problem | Candies (JOI18_candies) | C++11 | 141 ms | 65096 KB |
#include <bits/stdc++.h> using namespace std; #define pii pair < ll, ll > #define fr first #define sc second #define mk make_pair #define ll long long const ll inf = (ll)1e15 + 7; const int N = (int)2e5 + 7; int n; priority_queue < pii > q; ll a[N]; int prv[N], nxt[N]; main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); q.emplace(mk(a[i], i)); if (i > 1) prv[i] = i - 1; if (i < n) nxt[i] = i + 1; } ll ans = 0; for (int j = 1; j <= (n + 1) / 2; j++) { while (q.top().fr != a[q.top().sc]) q.pop(); int i = q.top().sc; ans += q.top().fr; printf("%lld\n", ans); int l = prv[i]; int r = nxt[i]; nxt[i] = nxt[r]; prv[i] = prv[l]; nxt[prv[l]] = i; prv[nxt[r]] = i; if (l && r) { a[i] = max(a[l] + a[r] - a[i], -inf); } else { a[i] = -inf; } a[l] = a[r] = -inf; q.emplace(mk(a[i], i)); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 592 KB | Output is correct |
4 | Correct | 3 ms | 736 KB | Output is correct |
5 | Correct | 3 ms | 736 KB | Output is correct |
6 | Correct | 3 ms | 776 KB | Output is correct |
7 | Correct | 3 ms | 820 KB | Output is correct |
8 | Correct | 3 ms | 856 KB | Output is correct |
9 | Correct | 3 ms | 876 KB | Output is correct |
10 | Correct | 3 ms | 896 KB | Output is correct |
11 | Correct | 3 ms | 916 KB | Output is correct |
12 | Correct | 3 ms | 936 KB | Output is correct |
13 | Correct | 3 ms | 952 KB | Output is correct |
14 | Correct | 3 ms | 968 KB | Output is correct |
15 | Correct | 3 ms | 988 KB | Output is correct |
16 | Correct | 3 ms | 988 KB | Output is correct |
17 | Correct | 3 ms | 1036 KB | Output is correct |
18 | Correct | 3 ms | 1176 KB | Output is correct |
19 | Correct | 3 ms | 1176 KB | Output is correct |
20 | Correct | 3 ms | 1300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 592 KB | Output is correct |
4 | Correct | 3 ms | 736 KB | Output is correct |
5 | Correct | 3 ms | 736 KB | Output is correct |
6 | Correct | 3 ms | 776 KB | Output is correct |
7 | Correct | 3 ms | 820 KB | Output is correct |
8 | Correct | 3 ms | 856 KB | Output is correct |
9 | Correct | 3 ms | 876 KB | Output is correct |
10 | Correct | 3 ms | 896 KB | Output is correct |
11 | Correct | 3 ms | 916 KB | Output is correct |
12 | Correct | 3 ms | 936 KB | Output is correct |
13 | Correct | 3 ms | 952 KB | Output is correct |
14 | Correct | 3 ms | 968 KB | Output is correct |
15 | Correct | 3 ms | 988 KB | Output is correct |
16 | Correct | 3 ms | 988 KB | Output is correct |
17 | Correct | 3 ms | 1036 KB | Output is correct |
18 | Correct | 3 ms | 1176 KB | Output is correct |
19 | Correct | 3 ms | 1176 KB | Output is correct |
20 | Correct | 3 ms | 1300 KB | Output is correct |
21 | Correct | 133 ms | 10780 KB | Output is correct |
22 | Correct | 140 ms | 12876 KB | Output is correct |
23 | Correct | 138 ms | 14628 KB | Output is correct |
24 | Correct | 103 ms | 16464 KB | Output is correct |
25 | Correct | 107 ms | 18240 KB | Output is correct |
26 | Correct | 102 ms | 19984 KB | Output is correct |
27 | Correct | 115 ms | 21944 KB | Output is correct |
28 | Correct | 116 ms | 23900 KB | Output is correct |
29 | Correct | 119 ms | 25856 KB | Output is correct |
30 | Correct | 126 ms | 27956 KB | Output is correct |
31 | Correct | 119 ms | 29912 KB | Output is correct |
32 | Correct | 120 ms | 31744 KB | Output is correct |
33 | Correct | 128 ms | 33476 KB | Output is correct |
34 | Correct | 125 ms | 35344 KB | Output is correct |
35 | Correct | 119 ms | 37024 KB | Output is correct |
36 | Correct | 135 ms | 38984 KB | Output is correct |
37 | Correct | 141 ms | 40872 KB | Output is correct |
38 | Correct | 138 ms | 42940 KB | Output is correct |
39 | Correct | 111 ms | 44748 KB | Output is correct |
40 | Correct | 105 ms | 46400 KB | Output is correct |
41 | Correct | 111 ms | 48200 KB | Output is correct |
42 | Correct | 131 ms | 50104 KB | Output is correct |
43 | Correct | 124 ms | 52096 KB | Output is correct |
44 | Correct | 119 ms | 54016 KB | Output is correct |
45 | Correct | 116 ms | 55992 KB | Output is correct |
46 | Correct | 136 ms | 57948 KB | Output is correct |
47 | Correct | 117 ms | 59904 KB | Output is correct |
48 | Correct | 121 ms | 61732 KB | Output is correct |
49 | Correct | 120 ms | 63468 KB | Output is correct |
50 | Correct | 122 ms | 65096 KB | Output is correct |