# | 제출 시각UTC-0 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98193 | onjo0127 | Candies (JOI18_candies) | C++11 | 189 ms | 10488 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long A[200009];
int L[200009], R[200009];
bool chk[200009];
int main() {
int N; scanf("%d",&N);
priority_queue<pair<long long, int> > pq;
for(int i=1; i<=N; i++) {
scanf("%d",&A[i]);
pq.push({A[i], i});
L[i] = i-1; R[i] = i+1;
}
pq.push({-1LL * 1e18, 0}); R[0] = 1; A[0] = -1LL * 1e18;
pq.push({-1LL * 1e18, N+1}); L[N+1] = N; A[N+1] = -1LL * 1e18;
long long ans = 0;
for(int i=1; i<=(N+1)/2; i++) {
long long v; int id;
while(1) {
tie(v, id) = pq.top(); pq.pop();
if(!chk[id]) break;
}
ans += v; printf("%lld\n",ans);
A[id] = A[L[id]] + A[R[id]] - A[id];
pq.push({A[id], id});
chk[L[id]] = chk[R[id]] = 1;
L[id] = L[L[id]]; R[id] = R[R[id]];
R[L[id]] = id; L[R[id]] = id;
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |