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;
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;
}
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++;
A.push_back(S);
A.push_back(T);
}
}
if (A.empty()) {
cout << add;
return;
}
sort(A.begin(), A.end());
int M = A.size();
if (K == 1) {
long long mid = A[(M - 1) / 2];
long long res = add;
for (int i = 0; i < M; i++) {
res += abs(A[i] - mid);
}
cout << res;
return;
}
}
# | 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... |