# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98181 | 2019-02-21T08:00:54 Z | onjo0127 | Candies (JOI18_candies) | C++11 | 4 ms | 512 KB |
#include <bits/stdc++.h> using namespace std; int A[200009], 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |