# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154972 | 2019-09-25T17:24:09 Z | karma | Candies (JOI18_candies) | C++14 | 5000 ms | 632 KB |
#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)1e18; typedef pair<int, 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) / 2; for(int i = 1; i <= n; ++i) { while(top = pq.top(), top.fi != a[top.se]) pq.pop(); 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5093 ms | 632 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 5093 ms | 632 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |