#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
const int MAXN = 1e5 + 10, MAX = 2e6 + 10;
int n, k, dif;
int a[MAXN], b[MAXN];
int s[2 * MAX];
ll cur, sol = 4e18;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin >> n >> k;
for(int i = 0;i < n; i++){
cin >> a[i];
}
for(int i = 0;i < n; i++){
cin >> b[i];
}
for(int i = 0;i < n; i++){
s[b[i] - a[i] + 1 + MAX] += 2;
}
for(int i = 0;i < n; i++){
int p = a[i] - MAX;
cur += b[i] - p + 1;
}
dif = -n;
for(int i = -MAX;i < MAX; i++){
sol = min(sol, cur);
dif += s[i + MAX];
cur += dif;
sol = min(sol, cur);
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
512 KB |
Output is correct |
2 |
Correct |
10 ms |
384 KB |
Output is correct |
3 |
Correct |
10 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
4984 KB |
Output is correct |
2 |
Correct |
33 ms |
2808 KB |
Output is correct |
3 |
Correct |
34 ms |
1272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
5104 KB |
Output is correct |
2 |
Correct |
34 ms |
2792 KB |
Output is correct |
3 |
Correct |
49 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
5084 KB |
Output is correct |
2 |
Correct |
39 ms |
2680 KB |
Output is correct |
3 |
Correct |
32 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
40 ms |
1144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
5092 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
1088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
5084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
5044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
1532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |