# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133902 | duality | Candies (JOI18_candies) | C++11 | 169 ms | 11052 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>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
int A[200000];
int l[200001],r[200001];
LLI rs[200001];
priority_queue<pair<LLI,pii> > H;
int main() {
int i;
int N;
scanf("%d",&N);
for (i = 0; i < N; i++) scanf("%d",&A[i]);
LLI ans = 0;
for (i = 0; i <= N; i++) {
l[i] = i-1,r[i] = i+1;
if (i < N) rs[i] = A[i],H.push(mp(A[i],mp(i,i+1)));
}
while (!H.empty()) {
int a = H.top().second.first,b = H.top().second.second;
LLI d = H.top().first;
H.pop();
if ((r[a] != b) || (l[b] != a)) continue;
ans += d,printf("%lld\n",ans);
if (l[a] != -1) r[l[a]] = r[b];
if (r[b] != N+1) l[r[b]] = l[a];
if ((l[a] != -1) && (r[b] != N+1)) {
H.push(mp(rs[l[a]]-d+rs[b],mp(l[a],r[b])));
rs[l[a]] = rs[l[a]]-d+rs[b];
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |