# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1071414 | phong | Candies (JOI18_candies) | C++17 | 2 ms | 2392 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>
#define ll long long
#define int long long
const int nmax = 3e5 + 5, N = 1e5;
const ll oo = 1e18 + 1, base = 311;
const int lg = 19, M = 10;
const ll mod = 998244353, mod2 = 1e9 + 5277;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
using namespace std;
int n, a[nmax];
int ans[nmax];
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
freopen("code.inp", "r", stdin);
freopen("code.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i];
multiset<pii> one, two;
a[0] = -oo;
a[n + 1] = -oo;
for(int i = 0; i <= n + 1; ++i){
one.insert({a[i], i});
two.insert({i, a[i]});
}
for(int i = 1; i <= (n + 1) / 2; ++i){
auto x = *one.rbegin();
ans[i] = ans[i - 1] + x.fi;
cout << ans[i] << endl;
// if(i == (n + 1) / 2) continue;
auto it = two.lower_bound({x.se, -oo});
--it;
pii s1 = *it;
one.erase(one.find({s1.se, s1.fi}));
two.erase(it++);
pii s2 = *it;
one.erase(one.find({s2.se, s2.fi}));
two.erase(it++);
pii s3 = *it;
one.erase(one.find({s3.se, s3.fi}));
two.erase(it++);
one.insert({s1.se + s3.se - s2.se, s2.fi});
two.insert({s2.fi, s1.se + s3.se - s2.se});
}
}
/*
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |