Submission #227191

# Submission time Handle Problem Language Result Execution time Memory
227191 2020-04-26T12:34:29 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;
set<pair<ll, ll> > 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();
        ans -= x.ff;
        swap(x.ff, x.ss);
        auto it = a.find(x);
        pair<ll, ll> s = x;
        s.ss *= -1;

        p.erase({it -> ss, it -> ff});
        it = a.erase(it);
        if(it != a.end()){
            s.ss += it -> ss;
            p.erase({it -> ss, it -> ff});
            it = a.erase(it);
        }
        if(it != a.begin()){
            --it;
            s.ss += it -> ss;
            p.erase({it -> ss, it -> ff});
            a.erase(it);
        }
        a.insert(s);
        p.insert({s.ss, s.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 -