# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334964 | ronnith | Simfonija (COCI19_simfonija) | C++14 | 52 ms | 3456 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>
#define trav(a, b) for(auto a : b)
#define mk make_pair
#define f first
#define s second
#define vi vector<int>
#define pb push_back
typedef long long ll;
using namespace std;
void re(vector<ll*> arr){
trav(e, arr)scanf("%lld", e);
}
ll n, k;
ll a[100000], b[100000];
ll check(ll x){
ll ans = 0;
for(int i = 0;i < n;i ++){
ans += abs(a[i] + x - b[i]);
}
return ans;
}
int main(){
// ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
re({&n,&k});
for(int i = 0;i < n;i ++){
re({&a[i]});
}
for(int i = 0;i < n;i ++){
re({&b[i]});
}
ll hi = 1e13;
ll lo = -1e13;
ll ans = LONG_LONG_MAX;
while(hi >= lo){
ll g1 = lo + (hi - lo) / 2;
ll g2 = g1 + 1;
ll a1 = check(g1), a2 = check(g2);
if(a1 == a2){
ans = a1;
break;
} else if(a1 < a2){
ans = min(ans, a1);
hi = g1 - 1;
} else if(a1 > a2){
ans = min(ans, a2);
lo = g1 + 1;
}
}
printf("%lld\n", 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... |