Submission #506019

#TimeUsernameProblemLanguageResultExecution timeMemory
506019sidonCandies (JOI18_candies)C++17
8 / 100
5079 ms10064 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'; 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...