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;
#define ll long long
#define pb push_back
#define sz size()
const int N = 1e5 + 5;
ll n, k, goshmaly, x[N], y[N];
char s[N], d[N];
vector <int> v;
int main () {
// freopen("input.txt", "r", stdin);
cin >> k >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i] >> x[i] >> d[i] >> y[i];
if (s[i] == d[i]) {
goshmaly += abs (x[i] - y[i]);
}
else {
goshmaly++;
v.pb (x[i] + y[i]);
}
}
if (!v.empty()) {
sort (v.begin(), v.end());
int n1 = (int)v.sz/2;
int med = v[n1]/2;
for(int i = 1; i <= n; i++){
if(s[i] != d[i]){
goshmaly += abs(med-x[i]) + abs(med-y[i]);
}
}
}
cout << goshmaly;
}
# | 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... |