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;
#define Z 200'002
int64_t N, K, L[Z], R[Z], r[Z], A[Z], sum;
priority_queue<array<int64_t, 2>> pq;
int main() {
cin >> N;
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;
R[0] = r[0] = r[N+1] = 1;
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';
for(int j = 0; j < 2; j++, swap(L, R))
r[L[i]] ? r[i]++ : v -= A[L[i]], r[L[i]] = 1, R[L[i] = L[L[i]]] = i;
if(!r[i]) pq.push({A[i] = -v, i});
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |