# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388904 | denkendoemeer | Candies (JOI18_candies) | C++14 | 135 ms | 10180 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e16
int nex[200005],pre[200005];
ll v[200005];
priority_queue<pair<ll,int>>pq;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%lld",&v[i]);
nex[i]=i+1;
pre[i]=i-1;
pq.push(make_pair(v[i],i));
}
nex[n]=0;
ll ans=0;
for(i=1;i<=(n+1)/2;i++){
while(pq.top().first!=v[pq.top().second])
pq.pop();
int x=pq.top().second,l=pre[x],r=nex[x];
ans+=v[x];
printf("%lld\n",ans);
pq.pop();
pre[nex[x]=nex[r]]=x;
nex[pre[x]=pre[l]]=x;
if (l && r)
v[x]=max((ll)-inf,v[l]+v[r]-v[x]);
else
v[x]=-inf;
v[l]=v[r]=-inf;
pq.push(make_pair(v[x],x));
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |