| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 129555 | BThero | Candies (JOI18_candies) | C++17 | 825 ms | 31352 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.
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll, ll> pll;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)2e5 + 5;
const ll INF = (ll)1e18;
ll arr[MAXN], ans[MAXN];
int n;
pll rev(pll x) {
return mp(x.se, x.fi);
}
void solve() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%lld", &arr[i]);
}
set<pll> S, S2;
for (int i = 0; i < n; ++i) {
S.insert(mp(arr[i], i));
S2.insert(mp(i, arr[i]));
}
for (int i = 1; i <= (n + 1) / 2; ++i) {
ans[i] = ans[i - 1] + S.rbegin() -> fi;
auto it = S2.lower_bound(rev(*S.rbegin()));
if (it == --S2.end()) {
S.erase(rev(*S2.rbegin()));
S2.erase(--S2.end());
if (!S2.empty()) {
S.erase(rev(*S2.rbegin()));
S2.erase(--S2.end());
}
}
else if (it == S2.begin()) {
S.erase(rev(*S2.begin()));
S2.erase(S2.begin());
if (!S2.empty()) {
S.erase(rev(*S2.begin()));
S2.erase(S2.begin());
}
}
else {
--it;
pll A = *it++;
pll B = *it++;
pll C = *it++;
ll nw = A.se + C.se - B.se;
S.erase(rev(A));
S2.erase(A);
S.erase(rev(B));
S2.erase(B);
S.erase(rev(C));
S2.erase(C);
S.insert(mp(nw, A.fi));
S2.insert(mp(A.fi, nw));
}
}
for (int i = 1; i <= (n + 1) / 2; ++i) {
printf("%lld\n", ans[i]);
}
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int tt = 1;
while (tt--) {
solve();
}
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
