#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
6084 KB |
Output is correct |
2 |
Correct |
64 ms |
7560 KB |
Output is correct |
3 |
Correct |
58 ms |
7588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
6124 KB |
Output is correct |
2 |
Correct |
59 ms |
7492 KB |
Output is correct |
3 |
Correct |
54 ms |
7488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
6124 KB |
Output is correct |
2 |
Correct |
67 ms |
6132 KB |
Output is correct |
3 |
Correct |
54 ms |
6084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
44 ms |
5828 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
6052 KB |
Output is correct |
2 |
Incorrect |
59 ms |
7152 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
5660 KB |
Output is correct |
2 |
Incorrect |
56 ms |
7388 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
5824 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
5908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
5952 KB |
Output is correct |
2 |
Correct |
57 ms |
7504 KB |
Output is correct |
3 |
Incorrect |
61 ms |
7516 KB |
Output isn't correct |