Submission #285900

#TimeUsernameProblemLanguageResultExecution timeMemory
285900YJUCandies (JOI18_candies)C++14
100 / 100
939 ms27452 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll MOD=1e9+7; const ll N=2e5+5; const ld pi=3.14159265359; const ll INF=(1LL<<60); #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(a) (ll)a.size() ll n,u[N],ans,vis[N]; multiset<pll,greater<pll> > ms; set<ll> idx; int main(){ //ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; REP1(i,n)cin>>u[i],ms.insert(mp(u[i],i)),idx.insert(i); u[0]=u[n+1]=-INF; REP1(i,(n+1)/2){ pll tmp=*ms.begin();ms.erase(ms.begin()); ans+=tmp.X; cout<<ans<<"\n"; if(i==(n+1)/2)break; ll l=(idx.lwb(tmp.Y)==idx.begin()?0:*prev(idx.lwb(tmp.Y))); ll r=(idx.lwb(tmp.Y+1)==idx.end()?0:*idx.lwb(tmp.Y+1)); u[tmp.Y]=-tmp.X+u[l]+u[r]; ms.erase(mp(u[l],l));ms.erase(mp(u[r],r)); idx.erase(l);idx.erase(r); ms.insert(mp(u[tmp.Y],tmp.Y)); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...