Submission #1215012

#TimeUsernameProblemLanguageResultExecution timeMemory
1215012og_matveychick1Candies (JOI18_candies)C++20
100 / 100
110 ms11432 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = (int) 2e5 + 10; priority_queue<array<int, 2>> pq; int n, ans, t, a[N], l[N], r[N], ok[N]; signed main() { cin >> n; t = (n + 1) / 2; a[0] = a[n + 1] = -2e18; for (int i = 1; i <= n; i++) cin >> a[i], pq.push({a[i], i}), l[i] = i - 1, r[i] = i + 1; while (t--) { while (ok[pq.top()[1]]) pq.pop(); auto [w, i] = pq.top(); pq.pop(); ok[l[i]] = ok[r[i]] = 1; cout << (ans += w) << "\n"; a[i] = a[l[i]] + a[r[i]] - a[i], pq.push({a[i], i}); l[i] = l[l[i]], r[l[i]] = i; r[i] = r[r[i]], l[r[i]] = i; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...