This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e18;
const int N = 5001;
void solve() {
int k,n;
cin >> k >> n;
assert(k == 1);
int ans = 0;
vi a;
vi v;
for (int i=1;i<=n;i++) {
char c1,c2;
int x1,x2;
cin >> c1 >> x1 >> c2 >> x2;
if (c1 == c2) {
ans+=abs(x1-x2);
continue;
}
v.push_back(x1),v.push_back(x2);
ans++;
}
sort(all(v));
int med = v[(v.size()+1)/2];
for (auto& it : v) ans+=abs(it-med);
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |