# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202255 | 2020-02-14T15:08:17 Z | quocnguyen1012 | Candies (JOI18_candies) | C++14 | 6 ms | 504 KB |
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back using namespace std; typedef long long ll; const int maxn = 2e5 + 5; const ll linf = 1e18; int N; ll a[maxn]; int prf[maxn], nxt[maxn]; priority_queue<pair<ll, int>> pq; bool del(int idx) { prf[nxt[idx]] = prf[idx]; nxt[prf[idx]] = nxt[idx]; } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("A.INP", "r")){ freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); } cin >> N; for (int i = 1; i <= N; ++i){ cin >> a[i]; prf[i] = i - 1; nxt[i] = i + 1; pq.push(mp(a[i], i)); } ll res = 0; for (int i = 1; i <= (N + 1) / 2; ++i){ while (pq.size() && a[pq.top().se] != pq.top().fi) pq.pop(); auto now = pq.top(); pq.pop(); res += now.fi; cout << res << '\n'; int pos = now.se; a[pos] = max(-linf, a[prf[pos]] + a[nxt[pos]] - a[pos]); int L = prf[pos], R = nxt[pos]; del(L); del(R); a[L] = a[R] = -linf; pq.push(mp(a[pos], pos)); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |