Submission #227204

# Submission time Handle Problem Language Result Execution time Memory
227204 2020-04-26T13:46:40 Z nvmdava Candies (JOI18_candies) C++17
0 / 100
7 ms 1024 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 200005
const ll MOD = 1'000'000'007;
const int INF = 0x3f3f3f3f;

set<pair<ll, ll> > a, p;
ll ans = 0;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    for(int x, i = 1; i <= n; ++i){
        cin>>x;
        x *= -1;
        a.insert({i, x});
        p.insert({x, i});
    }

    for(int i = 1; i <= (n + 1) / 2; ++i){
        pair<ll, ll> x = *p.begin();
        swap(x.ff, x.ss);
        ans -= x.ss;
        auto it = a.find(x);

        x.ss = 0;
        if(it != a.begin()){
            --it;
            x.ss += it -> ss;
            p.erase({it -> ss, it -> ff});
            it = a.erase(it);
        }
        x.ss -= it -> ss;
        p.erase({it -> ss, it -> ff});
        it = a.erase(it);
        x.ss += it -> ss;
        p.erase({it -> ss, it -> ff});
        it = a.erase(it);
        
        a.insert(x);
        p.insert({x.ss, x.ff});
        cout<<ans<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -