//#pragma GCC optimize("O3,unroll-loops")
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<math.h>
#include<iomanip>
#include<array>
#include<climits>
#include<assert.h>
//#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
#define str string
#define ins insert
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sqr(x) (x)*(x)
using namespace std;
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve() {
ll k,n;
cin >> k >> n;
ll d=0;
vector<pii> v;
for (ll i=0; i<n; i++) {
char a,b;
ll x,y;
cin >> a >> x >> b >> y;
if (a==b) {
d+=abs(x-y);
} else {
v.pb({x,y});
}
} n=v.size();
d+=n;
vector<ll> t;
for (ll i=0; i<n; i++) {
t.pb(v[i].fi);
t.pb(v[i].se);
} sort(t.begin(),t.end());
ll med=(t[n-1]+t[n])/2;
for (ll i=0; i<2*n; i++) {
d+=abs(med-t[i]);
} cout << d;
}
int main() {
//freopen("atlarge.in", "r", stdin);
//freopen("atlarge.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
//cin >> tt;
cout << fixed << setprecision(3);
for (int i=1; i<=tt; i++) {
//cout << "Case#" << i << ":\n";
solve();
}
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... |