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 <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
void solve(){
ll k, n;
cin >> k >> n;
vector<ll> a(1);
ll ans = 0;
for(int i = 1; i <= n; i++){
char s1, s2;
int l, r;
cin >> s1 >> l >> s2 >> r;
if(l > r) swap(l, r);
if(s1 == s2){
ans += r-l;
}else{
a.push_back(l);
a.push_back(r);
}
}
sort(a.begin()+1, a.end());
n = a.size()-1;
ans += n/2;
if(k == 1){
int m = (n+1)/2;
for(int i = 1; i <= n; i++){
ans += abs(a[m]-a[i]);
}
cout << ans;
return;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | 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... |