Submission #154974

#TimeUsernameProblemLanguageResultExecution timeMemory
154974karmaCandies (JOI18_candies)C++14
100 / 100
157 ms10340 KiB
#include<bits/stdc++.h> #define Task "test" #define ll long long #define pb emplace_back #define mp make_pair #define fi first #define se second using namespace std; const int N = int(5e5) + 5; const ll oo = (ll)1e15; typedef pair<ll, int> pii; int n, nxt[N], pre[N], p, l, r; ll a[N], res = 0; pii top; priority_queue<pii> pq; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); if(fopen(Task".inp", "r")) { freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout); } cin >> n; for(int i = 1; i <= n; ++i) { cin >> a[i]; nxt[i] = i + 1, pre[i] = i - 1; pq.push(mp(a[i], i)); } nxt[n] = 0, n = (n + 1) >> 1; for(int i = 1; i <= n; ++i) { while(top = pq.top(), top.fi != a[top.se]) { pq.pop(); if(pq.empty()) break; } p = top.se, l = pre[p], r = nxt[p], res += a[p]; cout << res << '\n'; pre[nxt[p] = nxt[r]] = p; nxt[pre[p] = pre[l]] = p; if(l && r) a[p] = a[l] + a[r] - a[p]; else a[p] = -oo; a[l] = a[r] = -oo; pq.push(mp(a[p], p)); } }

Compilation message (stderr)

candies.cpp: In function 'int main()':
candies.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...