#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e5+5;
int dist(int a, int b){
return abs(a-b);
}
signed main(){
int k,n;
cin>>k>>n;
int s=0;
vector<int>vc;
for(int i=1;i<=n;i++){
char x,y;
int a,b;
cin>>x>>a>>y>>b;
if(x==y){
s+=abs(a-b);
}
else{
s++;
vc.pb(a);
vc.pb(b);
}
}
sort(vc.begin(),vc.end());
for(int a:vc){
s+=dist(vc[(vc.size()/2)],a);
}
cout<<s;
}
# | 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... |