Submission #733628

#TimeUsernameProblemLanguageResultExecution timeMemory
733628SanguineChameleonPalembang 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> S; multiset<int>::iterator mid; long long left_sum = 0; long long right_sum = 0; int sz = 0; void clear() { S.clear(); left_sum = 0; right_sum = 0; sz = 0; } void insert(int x, int y) { if (x > y) { swap(x, y); } S.insert(x); S.insert(y); sz += 2; if (sz == 2) { mid = S.begin(); left_sum = x; right_sum = y; } else if (x > *mid) { mid++; left_sum += *mid; right_sum += x + y - *mid; } else if (y < *mid) { mid++; right_sum += *mid; left_sum += x + y - *mid; } else { left_sum += x; right_sum += y; } } 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...