#include <iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<math.h>
#define int long long
const int inf = 1e17;
const int maxn = 300005;
const int mod = (int)1e9 + 7;
using namespace std;
int32_t main()
{
int n, m; cin >> n >> m;
int a1 = 0, a2 = 0;
vector<int> a(n);
for (int i = 1; i < (n + m); ++i) {
int x, y; cin >> x >> y;
a.push_back(y);
}
sort(a.begin(), a.end());
for (auto x : a) a1 += x, a2 += x;
a1 /= a.size();
a2 = a1 + 1;
int ans = 0, r1 = 0, r2 = 0;
for (auto x : a) {
ans += abs(x - a[a.size() / 2]);
r1 += abs(x - a1);
r2 += abs(x - a2);
}
cout << min({ r1, r2, ans });
}
# | 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... |