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 <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define ll long long
using namespace std;
const ll INF = 1e15;
ll abs2(ll x){
return x < 0 ? -x : x;
}
int n, m;
vector<ll> v;
int main(){
cin >> n >> m;
for(int i = 2; i <= n + m; i++){
ll p, c;
cin >> p >> c;
v.pb(c);
}
sort(v.begin(), v.end());
ll ans = INF;
if(v.size() == 1){
cout << "0\n";
return 0;
} else {
for(int c : v){
ll res = 0;
for(int c2 : v){
res += abs2(c2 - c);
}
ans = min(ans, res);
}
}
cout << ans << "\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... |