Submission #87799

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
877992018-12-02 15:17:37KCSCPalembang Bridges (APIO15_bridge)C++14
100 / 100
165 ms45988 KiB
#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; } }
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...