# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98182 | onjo0127 | Candies (JOI18_candies) | C++11 | 3 ms | 512 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;
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;
pq.push({-1LL * 1e18, N+1}); L[N+1] = N;
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;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |