# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
961065 |
2024-04-11T13:14:32 Z |
Pring |
Candies (JOI18_candies) |
C++17 |
|
428 ms |
29904 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const int MXN = 200005;
const ll INF = 3.9e18;
int n;
ll a[MXN], ans;
set<pil> pos;
multiset<pli> S;
void PRE() {
FOR(i, 0, n + 2) {
pos.insert(mp(i, a[i]));
S.insert(mp(a[i], i));
}
}
void miku() {
cin >> n;
FOR(i, 1, n + 1) cin >> a[i];
a[0] = -INF;
a[n + 1] = -INF;
PRE();
FOR(i, 0, n / 2 + n % 2) {
// for (auto [v, j] : pos) debug(v, j);
auto [val, p] = *S.rbegin();
ans += val;
auto it = pos.find(mp(p, val));
auto itl = prev(it), itr = next(it);
auto [l, vl] = *itl;
auto [r, vr] = *itr;
FOR($, 0, 3) {
itl = pos.erase(itl);
}
S.erase(S.find(mp(val, p)));
S.erase(S.find(mp(vl, l)));
S.erase(S.find(mp(vr, r)));
pos.insert(mp(l, vl + vr - val));
S.insert(mp(vl + vr - val, l));
cout << ans << '\n';
}
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
744 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
744 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
732 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
600 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
732 KB |
Output is correct |
21 |
Correct |
411 ms |
29740 KB |
Output is correct |
22 |
Correct |
428 ms |
29788 KB |
Output is correct |
23 |
Correct |
415 ms |
29688 KB |
Output is correct |
24 |
Correct |
189 ms |
29356 KB |
Output is correct |
25 |
Correct |
182 ms |
29492 KB |
Output is correct |
26 |
Correct |
172 ms |
29512 KB |
Output is correct |
27 |
Correct |
200 ms |
29776 KB |
Output is correct |
28 |
Correct |
193 ms |
29844 KB |
Output is correct |
29 |
Correct |
184 ms |
29812 KB |
Output is correct |
30 |
Correct |
202 ms |
29804 KB |
Output is correct |
31 |
Correct |
222 ms |
29660 KB |
Output is correct |
32 |
Correct |
197 ms |
29776 KB |
Output is correct |
33 |
Correct |
303 ms |
29372 KB |
Output is correct |
34 |
Correct |
294 ms |
29592 KB |
Output is correct |
35 |
Correct |
279 ms |
29404 KB |
Output is correct |
36 |
Correct |
402 ms |
29660 KB |
Output is correct |
37 |
Correct |
416 ms |
29612 KB |
Output is correct |
38 |
Correct |
420 ms |
29752 KB |
Output is correct |
39 |
Correct |
201 ms |
29476 KB |
Output is correct |
40 |
Correct |
211 ms |
29324 KB |
Output is correct |
41 |
Correct |
174 ms |
29524 KB |
Output is correct |
42 |
Correct |
190 ms |
29772 KB |
Output is correct |
43 |
Correct |
183 ms |
29780 KB |
Output is correct |
44 |
Correct |
182 ms |
29748 KB |
Output is correct |
45 |
Correct |
190 ms |
29692 KB |
Output is correct |
46 |
Correct |
192 ms |
29776 KB |
Output is correct |
47 |
Correct |
198 ms |
29904 KB |
Output is correct |
48 |
Correct |
284 ms |
29356 KB |
Output is correct |
49 |
Correct |
281 ms |
29412 KB |
Output is correct |
50 |
Correct |
270 ms |
29508 KB |
Output is correct |