# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44349 | ruhanhabib39 | Candies (JOI18_candies) | C++17 | 902 ms | 28124 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;
const int MAXN = 2e5;
const long long INF = 1e16;
typedef set<pair<long long,long long>,greater<pair<long long,long long>>> inc_set;
long long N;
inc_set pos, val;
long long res[MAXN + 10];
int main() {
scanf("%lld", &N);
for(long long i = 0; i < N; i++) {
long long a; scanf("%lld", &a);
pos.emplace(i, a);
val.emplace(a, i);
}
pos.emplace(-1LL, -INF); pos.emplace(N, -INF);
val.emplace(-INF, -1LL); val.emplace(-INF, N);
long long ss = 0;
for(int i = 0; i < (N+1)/2; i++) {
auto valIt = val.begin();
ss += valIt->first;
res[i] = ss;
auto posIt = pos.find({valIt->second, valIt->first});
auto x = *prev(posIt);
auto y = *posIt;
auto z = *next(posIt);
for(auto it : {x,y,z}) {
pos.erase(it);
val.erase({it.second, it.first});
}
pos.insert({y.first, x.second + z.second - y.second});
val.insert({x.second + z.second - y.second, y.first});
}
for(int i = 0; i < (N + 1)/2; i++) {
printf("%lld\n", res[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |