Submission #227205

# Submission time Handle Problem Language Result Execution time Memory
227205 2020-04-26T13:47:34 Z nvmdava Candies (JOI18_candies) C++17
0 / 100
7 ms 640 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);
        if(it != a.end()){
            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 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -