# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
506006 |
2022-01-11T11:49:20 Z |
sidon |
Candies (JOI18_candies) |
C++17 |
|
2 ms |
332 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define Z 200'002
int N, K, L[Z], R[Z], r[Z];
ll A[Z], sum;
int main() {
cin >> N;
priority_queue<array<ll, 2>> pq;
for(int i = 1; i <= N; i++) {
cin >> A[i];
L[i] = i - 1, R[i] = i + 1;
pq.push({A[i], i});
}
R[N+1] = N+1, L[N+1] = N;
for(int k = 1; k*2 <= N+1; k++) {
while(r[pq.top()[1]]) pq.pop();
auto [v, i] = pq.top(); pq.pop();
cout << (sum += v) << '\n';
r[i] = r[L[i]] || r[R[i]];
if(!r[L[i]]) v -= A[L[i]], r[L[i]] = 1, R[L[i] = L[L[i]]] = i;
if(!r[R[i]]) v -= A[R[i]], r[R[i]] = 1, L[R[i] = R[R[i]]] = i;
if(!r[i]) pq.push({A[i] = -v, i});
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |