# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44348 | 2018-03-31T14:17:24 Z | ruhanhabib39 | Candies (JOI18_candies) | C++17 | 5 ms | 632 KB |
#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; int 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 632 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 632 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |