# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
95828 | Kastanda | Candies (JOI18_candies) | C++11 | 503 ms | 19600 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;
typedef long long ll;
const int N = 200005;
int n, L[N], R[N];
ll A[N];
set < pair < ll , int > > S;
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%lld", &A[i]);
L[i] = i - 1; R[i] = i + 1;
S.insert({A[i], i});
}
ll Mx = 0;
for (int i = 0; i < (n + 1 >> 1); i++)
{
int id = S.rbegin()->second;
S.erase(*S.rbegin());
Mx += A[id];
printf("%lld\n", Mx);
int le = L[id], ri = R[id];
S.erase({A[le], le});
S.erase({A[ri], ri});
if (le <= 0 || ri <= 0 || ri > n || le > n)
{
L[R[ri]] = 0;
R[L[le]] = n + 1;
continue;
}
A[id] = A[le] + A[ri] - A[id];
L[id] = L[le];
R[id] = R[ri];
L[R[id]] = id;
R[L[id]] = id;
S.insert({A[id], id});
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |