Submission #1088087

#TimeUsernameProblemLanguageResultExecution timeMemory
1088087DobromirAngelovCandies (JOI18_candies)C++14
0 / 100
1 ms536 KiB
#include<bits/stdc++.h> #define endl '\n' #define fi first #define se second using namespace std; const int MAXN=2e5+5; int n; long long a[MAXN]; int l[MAXN], r[MAXN]; priority_queue<pair<long long,int> > pq; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) { l[i]=r[i]=i; pq.push({a[i],i}); } long long ans=0; for(int i=1;i<=(n+1)/2;i++) { auto cur=pq.top(); pq.pop(); if(a[cur.se]!=cur.fi) {i--; continue;} int le=l[cur.se]-1; int ri=r[cur.se]+1; ans+=cur.fi; cout<<ans<<endl; l[le]=l[ri]=le; r[le]=r[ri]=ri; a[le]=a[ri]=-cur.fi+a[le]+a[ri]; pq.push({a[le],le}); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...