#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;
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));
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++)
sum += abs(a[i] - cur - b[i]);
ans = min(ans, sum);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
2812 KB |
Output is correct |
2 |
Correct |
35 ms |
2812 KB |
Output is correct |
3 |
Correct |
31 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2804 KB |
Output is correct |
2 |
Correct |
35 ms |
2812 KB |
Output is correct |
3 |
Correct |
34 ms |
2812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
2940 KB |
Output is correct |
2 |
Correct |
35 ms |
2812 KB |
Output is correct |
3 |
Correct |
33 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
2812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1086 ms |
2812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1088 ms |
2812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1094 ms |
2812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
2812 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1097 ms |
2804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |