# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154974 | 2019-09-25T17:28:02 Z | karma | Candies (JOI18_candies) | C++14 | 157 ms | 10340 KB |
#include<bits/stdc++.h> #define Task "test" #define ll long long #define pb emplace_back #define mp make_pair #define fi first #define se second using namespace std; const int N = int(5e5) + 5; const ll oo = (ll)1e15; typedef pair<ll, int> pii; int n, nxt[N], pre[N], p, l, r; ll a[N], res = 0; pii top; priority_queue<pii> pq; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; for(int i = 1; i <= n; ++i) { cin >> a[i]; nxt[i] = i + 1, pre[i] = i - 1; pq.push(mp(a[i], i)); } nxt[n] = 0, n = (n + 1) >> 1; for(int i = 1; i <= n; ++i) { while(top = pq.top(), top.fi != a[top.se]) { pq.pop(); if(pq.empty()) break; } p = top.se, l = pre[p], r = nxt[p], res += a[p]; cout << res << '\n'; pre[nxt[p] = nxt[r]] = p; nxt[pre[p] = pre[l]] = p; if(l && r) a[p] = a[l] + a[r] - a[p]; else a[p] = -oo; a[l] = a[r] = -oo; pq.push(mp(a[p], p)); } }
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 | 504 KB | Output is correct |
4 | Correct | 3 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 508 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 | 504 KB | Output is correct |
10 | Correct | 3 ms | 496 KB | Output is correct |
11 | Correct | 3 ms | 504 KB | Output is correct |
12 | Correct | 3 ms | 504 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 480 KB | Output is correct |
15 | Correct | 3 ms | 504 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 3 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 |
# | 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 | 504 KB | Output is correct |
4 | Correct | 3 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 508 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 | 504 KB | Output is correct |
10 | Correct | 3 ms | 496 KB | Output is correct |
11 | Correct | 3 ms | 504 KB | Output is correct |
12 | Correct | 3 ms | 504 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 480 KB | Output is correct |
15 | Correct | 3 ms | 504 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 3 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 | 157 ms | 10208 KB | Output is correct |
22 | Correct | 143 ms | 10216 KB | Output is correct |
23 | Correct | 130 ms | 10168 KB | Output is correct |
24 | Correct | 103 ms | 10084 KB | Output is correct |
25 | Correct | 104 ms | 9996 KB | Output is correct |
26 | Correct | 103 ms | 10080 KB | Output is correct |
27 | Correct | 118 ms | 10312 KB | Output is correct |
28 | Correct | 115 ms | 10248 KB | Output is correct |
29 | Correct | 117 ms | 10208 KB | Output is correct |
30 | Correct | 117 ms | 10208 KB | Output is correct |
31 | Correct | 119 ms | 10244 KB | Output is correct |
32 | Correct | 119 ms | 10212 KB | Output is correct |
33 | Correct | 119 ms | 9924 KB | Output is correct |
34 | Correct | 131 ms | 10004 KB | Output is correct |
35 | Correct | 122 ms | 10012 KB | Output is correct |
36 | Correct | 137 ms | 10208 KB | Output is correct |
37 | Correct | 134 ms | 10200 KB | Output is correct |
38 | Correct | 138 ms | 10340 KB | Output is correct |
39 | Correct | 103 ms | 10224 KB | Output is correct |
40 | Correct | 106 ms | 10080 KB | Output is correct |
41 | Correct | 104 ms | 10004 KB | Output is correct |
42 | Correct | 117 ms | 10240 KB | Output is correct |
43 | Correct | 118 ms | 10208 KB | Output is correct |
44 | Correct | 116 ms | 10248 KB | Output is correct |
45 | Correct | 120 ms | 10284 KB | Output is correct |
46 | Correct | 117 ms | 10208 KB | Output is correct |
47 | Correct | 122 ms | 10232 KB | Output is correct |
48 | Correct | 120 ms | 9984 KB | Output is correct |
49 | Correct | 120 ms | 10016 KB | Output is correct |
50 | Correct | 119 ms | 9992 KB | Output is correct |