제출 #733629

#제출 시각아이디문제언어결과실행 시간메모리
733629SanguineChameleonPalembang Bridges (APIO15_bridge)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; void just_do_it(); int main() { #ifdef KAMIRULEZ freopen("kamirulez.inp", "r", stdin); freopen("kamirulez.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); just_do_it(); return 0; } struct median { multiset<int> Sl; multiset<int> Sr; long long left_sum = 0; long long right_sum = 0; void clear() { Sl.clear(); Sr.clear(); left_sum = 0; right_sum = 0; } void insert(int x, int y) { if (Sl.empty()) { Sl.insert(x); Sr.insert(y); left_sum = x; right_sum = y; } else { if (x <= *Sr.begin()) { Sl.insert(x); left_sum += x; } else { Sr.insert(x); right_sum += x; } if (y <= *Sr.begin()) { Sl.insert(y); left_sum += y; } else { Sr.insert(y); right_sum += y; } if (Sl.size() > Sr.size()) { left_sum -= *Sl.rbegin(); right_sum += *Sl.rbegin(); Sr.insert(*Sl.rbegin()); Sl.erase(prev(Sl.end())); } else if (Sl.size() < Sr.size()) { right_sum -= *Sr.begin(); left_sum += *Sr.begin(); Sl.insert(*Sr.begin()); Sr.erase(Sr.begin()); } } } long long get() { return right_sum - left_sum; }; } med; void just_do_it() { int K, N; cin >> K >> N; vector<int> A; long long add = 0; for (int i = 0; i < N; i++) { char P, Q; int S, T; cin >> P >> S >> Q >> T; if (P == Q) { add += abs(S - T); } else { add++; if (K == 1) { med.insert(S, T); } } } if (K == 1) { cout << med.get() + add; return; } }
#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...