Submission #119624

#TimeUsernameProblemLanguageResultExecution timeMemory
119624shayan_pCandies (JOI18_candies)C++14
100 / 100
894 ms29920 KiB
// High above the clouds there is a rainbow... #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn=2e5+10,mod=1e9+7; const ll inf=1e18; int a[maxn]; set<pair<ll,pii> >st1; set<pair<pii,ll> >st2; ll ans; int main(){ ios_base::sync_with_stdio(false);cin.tie(0); int n; cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; st1.insert({a[i],{i,i}}); st2.insert({{i,i},a[i]}); } for(int _=0; _<(n+1)/2; _++){ auto xx= *st1.rbegin(); ans+= xx.F; cout<<ans<<"\n"; pair<pii,ll> x= {xx.S,xx.F}; auto it=st2.find(x); x.S*=-1; bool bad=0; if(it!=st2.begin()){ x.S+= prev(it)->S; x.F.F= prev(it)->F.F; st1.erase( {prev(it)->S, prev(it)->F} ); st2.erase(prev(it)); } else{ bad=1; } if(next(it)!=st2.end()){ x.S+= next(it)->S; x.F.S= next(it)->F.S; st1.erase( {next(it)->S, next(it)->F} ); st2.erase(next(it)); } else{ bad=1; } st1.erase(xx); st2.erase(it); if(bad==0){ st1.insert( {x.S,x.F} ); st2.insert( x ); } } return 0; } // Deathly mistakes: // * Read the problem curfully. // * Check maxn. // * Overflows.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...