Submission #1310393

#TimeUsernameProblemLanguageResultExecution timeMemory
1310393sebokxCandies (JOI18_candies)C++20
0 / 100
1 ms568 KiB
#include <bits/stdc++.h> #define st first #define nd second using namespace std; using ll = long long; const int N = 200'007; int n; ll t[N]; int lefts[N]; int rights[N]; bool blocked[N]; priority_queue<pair<ll, int>> que; ll solve(){ pair<ll, int> top = que.top(); while(blocked[top.nd]){ que.pop(); top = que.top(); } que.pop(); ll new_val = -top.st; if(lefts[top.nd] != -1){ blocked[lefts[top.nd]] = true; new_val += t[lefts[top.nd]]; lefts[top.nd] = lefts[lefts[top.nd]]; if(lefts[top.nd] != -1) rights[lefts[top.nd]] = top.nd; } if(rights[top.nd] != -1){ blocked[rights[top.nd]] = true; new_val += t[rights[top.nd]]; rights[top.nd] = rights[rights[top.nd]]; if(rights[top.nd] != -1) lefts[rights[top.nd]] = top.nd; } t[top.nd] = new_val; que.push({new_val, top.nd}); return top.st; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for(int i = 1; i <= n; i++) cin >> t[i]; for(int i = 1; i <= n; i++){ lefts[i] = i-1; rights[i] = i+1; } lefts[1] = -1; rights[n] = -1; for(int i = 1; i <= n; i++) que.push({t[i], i}); ll ans = 0; for(int i = 0; i < (n+1)/2; i++){ ans += solve(); cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...