#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;
vc.clear();
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;
}
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
4208 KB |
Output is correct |
2 |
Correct |
46 ms |
4208 KB |
Output is correct |
3 |
Correct |
40 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
4256 KB |
Output is correct |
2 |
Correct |
46 ms |
4192 KB |
Output is correct |
3 |
Correct |
43 ms |
4336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
4208 KB |
Output is correct |
2 |
Correct |
46 ms |
4208 KB |
Output is correct |
3 |
Correct |
41 ms |
4208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
4208 KB |
Output is correct |
2 |
Correct |
49 ms |
4212 KB |
Output is correct |
3 |
Correct |
257 ms |
4208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1096 ms |
4208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
4216 KB |
Output is correct |
2 |
Correct |
260 ms |
4208 KB |
Output is correct |
3 |
Execution timed out |
1092 ms |
4208 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
4208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
4208 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
262 ms |
4208 KB |
Output is correct |
2 |
Correct |
257 ms |
4208 KB |
Output is correct |
3 |
Execution timed out |
1098 ms |
4208 KB |
Time limit exceeded |