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 <algorithm>
#include <set>
using namespace std;
using ll = long long;
const int maxn = int(1e5) + 10;
const int inf = int(1e8);
const ll linf = 1ll<<60;
int n, k;
int a[maxn], b[maxn];
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
if (k == n) { cout << "0\n"; return 0; }
for (int i=1; i<=n; ++i) cin >> a[i];
for (int i=1; i<=n; ++i) cin >> b[i];
multiset<int> s;
for (int i=1; i<=n; ++i) s.insert(b[i]-a[i]);
for(;k--;) {
int dl = (*(++s.begin())) - (*s.begin());
int dr = (*(--s.end())) - (*(--(--s.end())));
if (dl > dr) s.erase(s.begin());
else s.erase(--s.end());
}
vector<int> v(s.begin(), s.end());
int t = v[v.size()/2];
ll ans = 0;
for (int i=0; i<int(v.size()); ++i) {
ans += abs(v[i]-t);
}
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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |