Submission #1075645

# Submission time Handle Problem Language Result Execution time Memory
1075645 2024-08-26T08:18:33 Z adaawf Candies (JOI18_candies) C++17
0 / 100
3 ms 600 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] = l + r - a[k];
                t.insert({a[k], k});
            }
        }
        cout << res << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -