Submission #1075646

# Submission time Handle Problem Language Result Execution time Memory
1075646 2024-08-26T08:18:46 Z adaawf Candies (JOI18_candies) C++17
100 / 100
471 ms 27336 KB
#include <iostream>
#include <set>
using namespace std;
long long int a[200005];
int main() {
    long long int n, res = 0;
    cin >> n;
    set<int> s;
    set<pair<long long int, int>> t;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s.insert(i);
        t.insert({a[i], i});
    }
    for (int i = 1; i <= (n + 1) / 2; i++) {
        long long int h = (*t.rbegin()).first, k = (*t.rbegin()).second;
        res += h;
        if (s.size() > 2) {
            if (k == *s.begin()) {
                t.erase({a[k], k}); s.erase(k);
                int l = *s.begin();
                t.erase({a[l], l}); s.erase(l);
            }
            else if (k == *s.rbegin()) {
                t.erase({a[k], k}); s.erase(k);
                int l = *s.rbegin();
                t.erase({a[l], l}); s.erase(l);
            }
            else {
                int l = *prev(s.lower_bound(k)), r = *s.upper_bound(k);
                t.erase({a[l], l}); t.erase({a[r], r});
                s.erase(l); s.erase(r);
                t.erase({a[k], k});
                a[k] = a[l] + a[r] - a[k];
                t.insert({a[k], k});
            }
        }
        cout << res << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 696 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 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 576 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 580 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 696 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 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 860 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 3 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 2 ms 576 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 2 ms 580 KB Output is correct
20 Correct 2 ms 604 KB Output is correct
21 Correct 390 ms 27292 KB Output is correct
22 Correct 386 ms 27336 KB Output is correct
23 Correct 455 ms 27172 KB Output is correct
24 Correct 217 ms 27056 KB Output is correct
25 Correct 211 ms 27132 KB Output is correct
26 Correct 218 ms 26988 KB Output is correct
27 Correct 218 ms 27220 KB Output is correct
28 Correct 253 ms 27216 KB Output is correct
29 Correct 258 ms 27116 KB Output is correct
30 Correct 285 ms 27236 KB Output is correct
31 Correct 241 ms 27220 KB Output is correct
32 Correct 279 ms 27264 KB Output is correct
33 Correct 304 ms 26964 KB Output is correct
34 Correct 379 ms 27052 KB Output is correct
35 Correct 348 ms 26960 KB Output is correct
36 Correct 434 ms 27088 KB Output is correct
37 Correct 471 ms 27092 KB Output is correct
38 Correct 452 ms 27312 KB Output is correct
39 Correct 247 ms 27220 KB Output is correct
40 Correct 235 ms 26936 KB Output is correct
41 Correct 236 ms 27140 KB Output is correct
42 Correct 254 ms 27136 KB Output is correct
43 Correct 244 ms 27152 KB Output is correct
44 Correct 228 ms 27220 KB Output is correct
45 Correct 266 ms 27316 KB Output is correct
46 Correct 290 ms 27328 KB Output is correct
47 Correct 285 ms 27244 KB Output is correct
48 Correct 302 ms 27040 KB Output is correct
49 Correct 336 ms 26976 KB Output is correct
50 Correct 305 ms 26884 KB Output is correct