# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47909 | 2018-05-08T14:53:04 Z | Just_Solve_The_Problem | Candies (JOI18_candies) | C++11 | 3 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; #define pii pair < int, int > #define fr first #define sc second #define mk make_pair #define ll long long const int inf = (int)1e9 + 7; const int N = (int)2e5 + 7; int n; priority_queue < pii > q; int a[N], prv[N], nxt[N]; main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); q.emplace(mk(a[i], i)); if (i > 1) prv[i] = i - 1; if (i < n) nxt[i] = i + 1; } ll ans = 0; for (int j = 1; j <= (n + 1) / 2; j++) { while (q.top().fr != a[q.top().sc]) q.pop(); int i = q.top().sc; ans += q.top().fr; printf("%lld\n", ans); int l = prv[i]; int r = nxt[i]; nxt[i] = nxt[r]; prv[i] = prv[l]; nxt[prv[l]] = i; prv[nxt[r]] = i; if (l && r) { a[i] = max(-a[i] + a[l] + a[r], -inf); } else { a[i] = -inf; } a[l] = a[r] = -inf; q.emplace(mk(a[i], i)); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |