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 endl '\n'
using namespace std;
typedef long long ll;
const ll MAXN = 3e5 + 10;
ll n,m;
ll w[MAXN];
void read()
{
cin >> n >> m;
for(int i = 2; i <= n + m; i++)
{
ll p,c;
cin >> p >> c;
w[i] = c;
}
}
void solve()
{
ll ans = 0;
sort(w + 1, w + n + m + 1);
ll mid = w[(n + m) / 2 + 1];
for(int i = 2; i <= n + m; i++)
{
ans += llabs(w[i] - mid);
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
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... |