Submission #532230

# Submission time Handle Problem Language Result Execution time Memory
532230 2022-03-02T14:15:13 Z pokmui9909 Candies (JOI18_candies) C++17
100 / 100
135 ms 13404 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define x first
#define y second
ll N;
ll A[200005];
ll L[200005];
ll R[200005];
ll Del[200005];

int main(){
    cin.tie(0) -> sync_with_stdio(false);

    cin >> N;
    priority_queue<pair<ll, ll>> PQ;
    for(int i = 1; i <= N; i++){
        cin >> A[i];
        PQ.push({A[i], i});
        L[i] = i - 1, R[i] = i + 1;
    }
    A[0] = A[N + 1] = -1e15;
    ll ans = 0;
    for(int i = 1; i <= (N + 1) / 2; i++){
        while(Del[PQ.top().y]) PQ.pop();
        pair<ll, ll> T = PQ.top(); PQ.pop();
        ans += T.x;
        cout << ans << '\n';
        Del[L[T.y]] = Del[R[T.y]] = 1;
        A[T.y] = A[L[T.y]] + A[R[T.y]] - A[T.y];
        L[T.y] = L[L[T.y]], R[T.y] = R[R[T.y]];
        R[L[T.y]] = T.y, L[R[T.y]] = T.y;
        PQ.push({A[T.y], T.y});
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 2 ms 412 KB Output is correct
15 Correct 2 ms 472 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 2 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 1 ms 420 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 1 ms 472 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 2 ms 412 KB Output is correct
15 Correct 2 ms 472 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 2 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 464 KB Output is correct
21 Correct 125 ms 13248 KB Output is correct
22 Correct 119 ms 13320 KB Output is correct
23 Correct 123 ms 13324 KB Output is correct
24 Correct 83 ms 13080 KB Output is correct
25 Correct 75 ms 13112 KB Output is correct
26 Correct 79 ms 13068 KB Output is correct
27 Correct 85 ms 13276 KB Output is correct
28 Correct 135 ms 13236 KB Output is correct
29 Correct 87 ms 13168 KB Output is correct
30 Correct 83 ms 13284 KB Output is correct
31 Correct 98 ms 13344 KB Output is correct
32 Correct 84 ms 13168 KB Output is correct
33 Correct 92 ms 12980 KB Output is correct
34 Correct 89 ms 12980 KB Output is correct
35 Correct 94 ms 13108 KB Output is correct
36 Correct 110 ms 13264 KB Output is correct
37 Correct 104 ms 13236 KB Output is correct
38 Correct 103 ms 13224 KB Output is correct
39 Correct 78 ms 13084 KB Output is correct
40 Correct 73 ms 12996 KB Output is correct
41 Correct 78 ms 13104 KB Output is correct
42 Correct 81 ms 13200 KB Output is correct
43 Correct 85 ms 13336 KB Output is correct
44 Correct 96 ms 13404 KB Output is correct
45 Correct 82 ms 13236 KB Output is correct
46 Correct 82 ms 13236 KB Output is correct
47 Correct 86 ms 13248 KB Output is correct
48 Correct 88 ms 12988 KB Output is correct
49 Correct 113 ms 12984 KB Output is correct
50 Correct 94 ms 13096 KB Output is correct