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<vector>
#include<string>
#include<algorithm>
#include<set>
#include<numeric>
#include<map>
#include<queue>
#include<stack>
#include<math.h>
#include<iomanip>
#include<array>
//#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define double 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 n,k;
cin >> k >> n;
vector<ll> t;
ll d=0;
for (ll i=0; i<n; i++) {
char p,q;
ll a,b;
cin >> p >> a >> q >> b;
if (p==q) {
d+=abs(a-b);
} else {
t.pb(a);
t.pb(b);
}
} sort(t.begin(),t.end());
ll sz=t.size();
ll med=t[(sz-1)/2];
d+=sz/2;
for (ll i=0; i<sz; i++) {
d+=abs(med-t[i]);
} cout << d;
}
int main() {
//freopen("hayfeast.in", "r", stdin);
//freopen("hayfeast.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
//cin >> tt;
//cout << setprecision(20);
while (tt--) {
//cout << "Case#" << tt <<":\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... |