Submission #532228

#TimeUsernameProblemLanguageResultExecution timeMemory
532228pokmui9909Candies (JOI18_candies)C++17
0 / 100
1 ms444 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define x first #define y second ll N; ll A[200005]; ll L[200005]; ll R[200005]; ll Del[200005]; int main(){ cin.tie(0) -> sync_with_stdio(false); cin >> N; priority_queue<pair<ll, ll>> PQ; for(int i = 1; i <= N; i++){ cin >> A[i]; PQ.push({A[i], i}); L[i] = i - 1, R[i] = i + 1; } ll ans = 0; for(int i = 1; i <= (N + 1) / 2; i++){ while(Del[PQ.top().y]) PQ.pop(); pair<ll, ll> T = PQ.top(); PQ.pop(); ans += T.x; cout << ans << '\n'; Del[L[T.y]] = Del[R[T.y]] = 1; A[T.y] = A[L[T.y]] + A[R[T.y]] - A[T.y]; L[T.y] = L[L[T.y]], R[T.y] = R[R[T.y]]; R[L[T.y]] = T.y, L[R[T.y]] = T.y; PQ.push({A[T.y], T.y}); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...