# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87799 | KCSC | Palembang Bridges (APIO15_bridge) | C++14 | 165 ms | 45988 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 DIM = 100005;
long long lst1[DIM], lst2[DIM];
vector<pair<int, int>> arr;
void insert(auto &lef, auto &rig, long long &lsum, long long &rsum, int x) {
if (!lef.size() or x <= lef.top()) {
lsum += x; lef.push(x); }
else {
rsum += x; rig.push(x); } }
void balance(auto &lef, auto &rig, long long &lsum, long long &rsum) {
while ((int) rig.size() - (int) lef.size() > 1) {
lsum += rig.top(); rsum -= rig.top(); lef.push(rig.top()); rig.pop(); }
while ((int) lef.size() - (int) rig.size() > 1) {
rsum += lef.top(); lsum -= lef.top(); rig.push(lef.top()); lef.pop(); } }
void solve(long long lst[DIM]) {
long long lsum = 0, rsum = 0;
priority_queue<int, vector<int>, less<int>> lef;
priority_queue<int, vector<int>, greater<int>> rig;
for (int i = 1; i <= (int) arr.size(); ++i) {
insert(lef, rig, lsum, rsum, arr[i - 1].first);
insert(lef, rig, lsum, rsum, arr[i - 1].second);
balance(lef, rig, lsum, rsum);
lst[i] = 1LL * lef.top() * (lef.size() - rig.size()) - lsum + rsum; } }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |