제출 #388904

#제출 시각아이디문제언어결과실행 시간메모리
388904denkendoemeerCandies (JOI18_candies)C++14
100 / 100
135 ms10180 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

candies.cpp: In function 'int main()':
candies.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
candies.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%lld",&v[i]);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...