Submission #506021

#TimeUsernameProblemLanguageResultExecution timeMemory
506021sidonCandies (JOI18_candies)C++17
100 / 100
198 ms11312 KiB
#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'; r[L[i]] ? r[i]++ : v -= A[L[i]], r[L[i]]++, R[L[i] = L[L[i]]] = i; r[R[i]] ? r[i]++ : v -= A[R[i]], r[R[i]]++, L[R[i] = R[R[i]]] = i; if(!r[i]) pq.push({A[i] = -v, i}); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...