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 <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mxn = 100000;
int n, k;
vector<pi> p;
vector<int> v;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k >> n;
ll ret = 0;
for(int i = 0; i < n; i++){
char a, b;
int x, y;
cin >> a >> x >> b >> y;
if(x > y) swap(x, y);
ret += y - x;
if(a != b) ret++, p.push_back({x, y}), v.push_back(x), v.push_back(y);
}
sort(v.begin(), v.end());
if(!v.empty()){
int x = v[v.size() / 2];
for(pi i : p){
if(x < i.f) ret += 2 * (i.f - x);
if(x > i.s) ret += 2 * (x - i.s);
}
}
cout << ret << endl;
return 0;
}
# | 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... |