# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
204944 | ics0503 | Cake 3 (JOI19_cake3) | C++17 | 3608 ms | 23652 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<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
long long n, m, allSum = 0;
multiset<long long >L, R; // R is big
void balance() {
if (L.size() == 0 || R.size() == 0)return;
if (R.size() < m) {
long long lmax = (*L.rbegin());
L.erase(L.find(lmax)); R.insert(lmax);
allSum += lmax;
return;
}
long long lmax = (*L.rbegin()), rmin = (*R.begin());
if (lmax > rmin) {
L.erase(L.find(lmax)); R.erase(R.find(rmin));
L.insert(rmin); R.insert(lmax);
allSum += lmax - rmin;
}
}
void add(long long x) {
if (R.size() < m) { R.insert(x); allSum += x; }
else L.insert(x);
balance();
}
void del(long long x) {
if (L.find(x) != L.end())L.erase(L.find(x));
else { R.erase(R.find(x)); allSum -= x; }
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |