#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int NMAX = 2e5;
int k, n, ind;
ll answer;
pair<int, int> houses[NMAX + 1];
int a[2 * NMAX + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> k >> n;
for(int i = 1; i <= n; i++) {
char z1, z2;
int x, y;
cin >> z1 >> x >> z2 >> y;
if(z1 != z2) {
houses[++ind] = {x, y};
}
else {
answer += abs(x - y);
}
}
n = ind;
ind = 0;
for(int i = 1; i <= n; i++) {
a[++ind] = houses[i].first;
a[++ind] = houses[i].second;
}
sort(a + 1, a + ind + 1);
for(int i = 1; i <= ind; i++) {
answer += abs(a[i] - a[ind / 2 + 1]);
}
answer += n;
cout << answer << '\n';
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... |