Submission #206900

# Submission time Handle Problem Language Result Execution time Memory
206900 2020-03-05T19:22:56 Z achibasadzishvili Candies (JOI18_candies) C++14
0 / 100
7 ms 632 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,a[200005],ans;
set<pair<ll,ll> >st;
set<ll>ind;
set<pair<ll,ll> >::iterator it;
set<ll>::iterator itt;
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    
    for(int i=1; i<=n; i++){
        cin >> a[i];
        ind.insert(i);
        st.insert(mp(a[i] , i));
    }
    
    for(int i=1; i<=(n + 1) / 2; i++){
        it = st.end();
        it--;
        ll val = (*it).f , cur = (*it).s;
        st.erase(it);
        ans += val;
        ind.erase(ind.find(cur));
        itt = ind.upper_bound(cur);
        a[cur] = -a[cur];
        if(itt != ind.end()){
            a[cur] += a[(*itt)];
            st.erase(st.find(mp(a[(*itt)] , (*itt))));
            ind.erase(itt);
        }
        itt = ind.upper_bound(cur);
        if(ind.size() && itt != ind.begin()){
            itt--;
            a[cur] += a[(*itt)];
            st.erase(st.find(mp(a[(*itt)] , (*itt))));
            ind.erase(itt);
        }
        st.insert(mp(a[cur] , cur));
        ind.insert(cur);
        cout << ans << '\n';
    }
    
    
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -