# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
154974 | karma | Candies (JOI18_candies) | C++14 | 157 ms | 10340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |