#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define MP make_pair
#define PB push_back
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const ll N = 100100;
const ll OO = 1e18;
vector<ll> qr, vc;
ll n, k, a[N], b[N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
for (ll i = 0; i < n; i++)
cin >> a[i];
for (ll j = 0; j < n; j++){
cin >> b[j];
qr.PB(a[j] - b[j]);
}
ll ans = OO;
sort(all(qr));
qr.resize(unique(all(qr)) - qr.begin());
int lbd = 0, rbd = sz(qr) - 1;
if (k == 0){
lbd = rbd = n / 2;
}
for (int cr = lbd; cr <= rbd; cr++){
ll cur = qr[cr];
ll sum = 0;
for (int i = 0; i < n; i++)
vc.PB(abs(a[i] - cur - b[i]));
sort(all(vc));
for (int i = 0; i + k < n; i++)
sum += vc[i];
ans = min(ans, sum);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
4208 KB |
Output is correct |
2 |
Correct |
44 ms |
4208 KB |
Output is correct |
3 |
Correct |
38 ms |
4208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
4208 KB |
Output is correct |
2 |
Correct |
43 ms |
4208 KB |
Output is correct |
3 |
Correct |
43 ms |
4208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
4212 KB |
Output is correct |
2 |
Correct |
43 ms |
4208 KB |
Output is correct |
3 |
Correct |
38 ms |
4212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
6900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1091 ms |
35780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
7020 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
35760 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
19292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1093 ms |
35608 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1096 ms |
35836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |