# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100236 | FutymyClone | Simfonija (COCI19_simfonija) | C++14 | 430 ms | 2352 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, a[N], b[N];
long long solve (int x) {
vector <int> vec;
for (int i = 1; i <= n; i++) vec.push_back(abs(a[i] + x - b[i]));
sort(vec.begin(), vec.end(), greater <int>());
long long ans = 0;
for (int i = m; i < vec.size(); i++) ans += vec[i];
return ans;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
int l = -5e6, r = 5e6, ans = -1e9;
while (l <= r) {
int mid = (l + r) / 2;
long long lef = solve(mid), rig = solve(mid + 1);
if (lef == rig) {
ans = mid;
break;
}
if (lef < rig) r = mid - 1;
else l = mid + 1;
}
if (ans < -5e8) ans = l;
cout << solve(ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |