# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
172466 | mhy908 | Candies (JOI18_candies) | C++14 | 163 ms | 11972 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL llinf=9000000000000000000;
const int inf=2000000000;
int n;
LL arr[200010], pr[200010], ne[200010];
priority_queue<pair<LL, int> > pq;
int main()
{
scanf("%d", &n);
for(int i=1; i<=n; i++){
scanf("%lld", &arr[i]);
pq.push(mp(arr[i], i));
if(i>1)pr[i]=i-1;
if(i<n)ne[i]=i+1;
}
LL ans=0;
for(int i=1; i<=(n+1)/2; i++){
while(pq.top().F!=arr[pq.top().S])pq.pop();
int t=pq.top().S;
ans+=arr[t];
printf("%lld\n", ans);
int l=pr[t];
int r=ne[t];
ne[t]=ne[r];
pr[t]=pr[l];
pr[ne[r]]=t;
ne[pr[l]]=t;
if(l&&r)arr[t]=max(arr[l]+arr[r]-arr[t], -llinf);
else arr[t]=-llinf;
arr[l]=arr[r]=-llinf;
pq.push(mp(arr[t], t));
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |