Submission #882284

#TimeUsernameProblemLanguageResultExecution timeMemory
882284NK_Candies (JOI18_candies)C++17
100 / 100
96 ms14540 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define sz(x) int(x.size()) #define pb push_back using ll = long long; const ll INFL = ll(3e18); const int INF = int(1e9) + 1008; template<class T> using V = vector<T>; using vi = vector<int>; using vl = vector<ll>; template<class T> using pq = priority_queue<T, vector<T>, less<T>>; int main() { cin.tie(0)->sync_with_stdio(0); int N; cin >> N; vl A(N); for(auto& x : A) cin >> x; vi prv(N + 1, -1), nxt(N + 1, N + 1), vis(N + 1); pq<array<ll, 3>> q; for(int i = 0; i < N; i++) { prv[i + 1] = i, nxt[i] = i + 1; q.push({A[i], i, i + 1}); } int take = 0; ll ans = 0; while(take < (N + 1) / 2) { auto [w, u, v] = q.top(); q.pop(); if (vis[u] || vis[v]) continue; vis[u] = vis[v] = 1; ans += w; take++; cout << ans << nl; if (prv[u] < 0 || nxt[v] > N) continue; nxt[prv[u]] = nxt[v]; prv[nxt[v]] = prv[u]; A[prv[u]] += A[v] - A[u]; q.push({A[prv[u]], prv[u], nxt[v]}); } exit(0-0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...