#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 = max(0, 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 |
1 |
Correct |
1 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
7516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
7560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
7520 KB |
Output is correct |
2 |
Correct |
65 ms |
7548 KB |
Output is correct |
3 |
Incorrect |
57 ms |
7556 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
6668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
7464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
50 ms |
7148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
7300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
7416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
7464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |