# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
882284 |
2023-12-02T23:38:39 Z |
NK_ |
Candies (JOI18_candies) |
C++17 |
|
96 ms |
14540 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define sz(x) int(x.size())
#define pb push_back
using ll = long long;
const ll INFL = ll(3e18);
const int INF = int(1e9) + 1008;
template<class T> using V = vector<T>;
using vi = vector<int>;
using vl = vector<ll>;
template<class T> using pq = priority_queue<T, vector<T>, less<T>>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vl A(N); for(auto& x : A) cin >> x;
vi prv(N + 1, -1), nxt(N + 1, N + 1), vis(N + 1);
pq<array<ll, 3>> q; for(int i = 0; i < N; i++) {
prv[i + 1] = i, nxt[i] = i + 1;
q.push({A[i], i, i + 1});
}
int take = 0; ll ans = 0;
while(take < (N + 1) / 2) {
auto [w, u, v] = q.top(); q.pop();
if (vis[u] || vis[v]) continue;
vis[u] = vis[v] = 1;
ans += w; take++;
cout << ans << nl;
if (prv[u] < 0 || nxt[v] > N) continue;
nxt[prv[u]] = nxt[v];
prv[nxt[v]] = prv[u];
A[prv[u]] += A[v] - A[u];
q.push({A[prv[u]], prv[u], nxt[v]});
}
exit(0-0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
628 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
612 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
628 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
628 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
612 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
628 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
464 KB |
Output is correct |
21 |
Correct |
82 ms |
13788 KB |
Output is correct |
22 |
Correct |
96 ms |
13476 KB |
Output is correct |
23 |
Correct |
86 ms |
13772 KB |
Output is correct |
24 |
Correct |
74 ms |
14540 KB |
Output is correct |
25 |
Correct |
68 ms |
13376 KB |
Output is correct |
26 |
Correct |
68 ms |
12900 KB |
Output is correct |
27 |
Correct |
74 ms |
14280 KB |
Output is correct |
28 |
Correct |
84 ms |
14148 KB |
Output is correct |
29 |
Correct |
76 ms |
13524 KB |
Output is correct |
30 |
Correct |
77 ms |
13116 KB |
Output is correct |
31 |
Correct |
84 ms |
13240 KB |
Output is correct |
32 |
Correct |
78 ms |
13780 KB |
Output is correct |
33 |
Correct |
78 ms |
14284 KB |
Output is correct |
34 |
Correct |
94 ms |
13432 KB |
Output is correct |
35 |
Correct |
85 ms |
13764 KB |
Output is correct |
36 |
Correct |
94 ms |
12980 KB |
Output is correct |
37 |
Correct |
83 ms |
13164 KB |
Output is correct |
38 |
Correct |
83 ms |
13752 KB |
Output is correct |
39 |
Correct |
67 ms |
13316 KB |
Output is correct |
40 |
Correct |
74 ms |
13492 KB |
Output is correct |
41 |
Correct |
68 ms |
13484 KB |
Output is correct |
42 |
Correct |
75 ms |
14284 KB |
Output is correct |
43 |
Correct |
76 ms |
13888 KB |
Output is correct |
44 |
Correct |
74 ms |
13740 KB |
Output is correct |
45 |
Correct |
76 ms |
13232 KB |
Output is correct |
46 |
Correct |
78 ms |
13500 KB |
Output is correct |
47 |
Correct |
86 ms |
13204 KB |
Output is correct |
48 |
Correct |
78 ms |
13508 KB |
Output is correct |
49 |
Correct |
87 ms |
13864 KB |
Output is correct |
50 |
Correct |
88 ms |
13632 KB |
Output is correct |