Submission #136500

#TimeUsernameProblemLanguageResultExecution timeMemory
136500Osama_AlkhodairyCandies (JOI18_candies)C++17
0 / 100
7 ms504 KiB
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n; vector <ll> a; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; a.resize(n); for(auto &i : a) cin >> i; set <int> alive; set <pair <ll, int> > s; for(int i = 0 ; i < n ; i++){ alive.insert(i); s.insert(make_pair(a[i], i)); } ll ans = 0; for(int itt = 0 ; itt < (n + 1) / 2 ; itt++){ auto top = *--s.end(); s.erase(--s.end()); ans += top.first; cout << ans << endl; int pos = top.second; alive.erase(pos); a[pos] *= -1; auto it = alive.upper_bound(pos); if(it != alive.end()){ a[pos] += a[*it]; s.erase(make_pair(a[*it], *it)); alive.erase(*it); } it = alive.upper_bound(pos); if(it != alive.begin()){ it--; a[pos] += a[*it]; s.erase(make_pair(a[*it], *it)); alive.erase(*it); } alive.insert(pos); s.insert(make_pair(a[pos], pos)); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...