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>
#define ll long long
using namespace std;
ll ans,n,k,i,x,y,l,a[200005];
char s,t;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> k >> n;
for(i=1;i<=n;i++){
cin >> s >> x >> t >> y;
if(s==t) ans+=abs(x-y);
else{
ans++;
l++;
a[l]=x;
l++;
a[l]=y;
}
}
sort(a+1,a+l+1);
x=a[(l+1)/2];
//cout << x << " ";
for(i=1;i<=l;i++){
ans+=abs(x-a[i]);
}
cout << ans;
}
# | 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... |