# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44438 | 2018-04-02T07:22:08 Z | ssnsarang2023 | Candies (JOI18_candies) | C++17 | 169 ms | 10316 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pli; const int N = (int)2e5+5; const ll oo = (ll)1e16; int n, nxt[N], pre[N]; ll a[N]; priority_queue<pli> pq; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld", &a[i]); nxt[i] = i + 1, pre[i] = i - 1; pq.push(pli(a[i], i)); } nxt[n] = 0; ll ans = 0; for (int i = 1; i <= ((n + 1) >> 1); ++i) { for (; pq.top().first != a[pq.top().second]; pq.pop()); int x = pq.top().second, l = pre[x], r = nxt[x]; printf("%lld\n", ans += a[x]); pq.pop(); pre[nxt[x] = nxt[r]] = x; nxt[pre[x] = pre[l]] = x; a[x] = l && r ? max(-oo, a[l] + a[r] - a[x]) : -oo; a[l] = a[r] = -oo; pq.push(pli(a[x], x)); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 340 KB | Output is correct |
2 | Correct | 3 ms | 484 KB | Output is correct |
3 | Correct | 3 ms | 580 KB | Output is correct |
4 | Correct | 4 ms | 580 KB | Output is correct |
5 | Correct | 3 ms | 732 KB | Output is correct |
6 | Correct | 4 ms | 732 KB | Output is correct |
7 | Correct | 3 ms | 732 KB | Output is correct |
8 | Correct | 3 ms | 732 KB | Output is correct |
9 | Correct | 3 ms | 764 KB | Output is correct |
10 | Correct | 3 ms | 764 KB | Output is correct |
11 | Correct | 3 ms | 764 KB | Output is correct |
12 | Correct | 3 ms | 764 KB | Output is correct |
13 | Correct | 4 ms | 764 KB | Output is correct |
14 | Correct | 3 ms | 764 KB | Output is correct |
15 | Correct | 3 ms | 764 KB | Output is correct |
16 | Correct | 3 ms | 764 KB | Output is correct |
17 | Correct | 3 ms | 824 KB | Output is correct |
18 | Correct | 3 ms | 876 KB | Output is correct |
19 | Correct | 3 ms | 900 KB | Output is correct |
20 | Correct | 3 ms | 900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 340 KB | Output is correct |
2 | Correct | 3 ms | 484 KB | Output is correct |
3 | Correct | 3 ms | 580 KB | Output is correct |
4 | Correct | 4 ms | 580 KB | Output is correct |
5 | Correct | 3 ms | 732 KB | Output is correct |
6 | Correct | 4 ms | 732 KB | Output is correct |
7 | Correct | 3 ms | 732 KB | Output is correct |
8 | Correct | 3 ms | 732 KB | Output is correct |
9 | Correct | 3 ms | 764 KB | Output is correct |
10 | Correct | 3 ms | 764 KB | Output is correct |
11 | Correct | 3 ms | 764 KB | Output is correct |
12 | Correct | 3 ms | 764 KB | Output is correct |
13 | Correct | 4 ms | 764 KB | Output is correct |
14 | Correct | 3 ms | 764 KB | Output is correct |
15 | Correct | 3 ms | 764 KB | Output is correct |
16 | Correct | 3 ms | 764 KB | Output is correct |
17 | Correct | 3 ms | 824 KB | Output is correct |
18 | Correct | 3 ms | 876 KB | Output is correct |
19 | Correct | 3 ms | 900 KB | Output is correct |
20 | Correct | 3 ms | 900 KB | Output is correct |
21 | Correct | 164 ms | 9972 KB | Output is correct |
22 | Correct | 154 ms | 9972 KB | Output is correct |
23 | Correct | 169 ms | 9976 KB | Output is correct |
24 | Correct | 112 ms | 10028 KB | Output is correct |
25 | Correct | 110 ms | 10028 KB | Output is correct |
26 | Correct | 116 ms | 10184 KB | Output is correct |
27 | Correct | 131 ms | 10184 KB | Output is correct |
28 | Correct | 132 ms | 10240 KB | Output is correct |
29 | Correct | 128 ms | 10240 KB | Output is correct |
30 | Correct | 128 ms | 10240 KB | Output is correct |
31 | Correct | 130 ms | 10312 KB | Output is correct |
32 | Correct | 128 ms | 10312 KB | Output is correct |
33 | Correct | 143 ms | 10312 KB | Output is correct |
34 | Correct | 167 ms | 10312 KB | Output is correct |
35 | Correct | 143 ms | 10316 KB | Output is correct |
36 | Correct | 152 ms | 10316 KB | Output is correct |
37 | Correct | 163 ms | 10316 KB | Output is correct |
38 | Correct | 161 ms | 10316 KB | Output is correct |
39 | Correct | 141 ms | 10316 KB | Output is correct |
40 | Correct | 110 ms | 10316 KB | Output is correct |
41 | Correct | 113 ms | 10316 KB | Output is correct |
42 | Correct | 136 ms | 10316 KB | Output is correct |
43 | Correct | 131 ms | 10316 KB | Output is correct |
44 | Correct | 128 ms | 10316 KB | Output is correct |
45 | Correct | 136 ms | 10316 KB | Output is correct |
46 | Correct | 128 ms | 10316 KB | Output is correct |
47 | Correct | 137 ms | 10316 KB | Output is correct |
48 | Correct | 139 ms | 10316 KB | Output is correct |
49 | Correct | 140 ms | 10316 KB | Output is correct |
50 | Correct | 141 ms | 10316 KB | Output is correct |