Submission #100328

#TimeUsernameProblemLanguageResultExecution timeMemory
100328tpoppoSimfonija (COCI19_simfonija)C++14
11 / 110
888 ms4092 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int MAXN = 1e5 + 10; int n, k; int a[MAXN]; int b[MAXN]; int sim(int x){ vector<int> v; for(int i=0;i<n;i++) v.push_back( abs(a[i]-b[i] + x)); sort(v.begin(),v.end()); int sm = 0; for(int i=0;i<n-k;i++) sm += v[i]; return sm; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> k; for(int i=0;i<n;i++) cin >> a[i]; for(int i=0;i<n;i++) cin >> b[i]; int l = -2e6; int r = 2e6; //for(int i=-20;i<20;i++) cout<<i<<": "<<sim(i)<<endl; while(l<r){ //cout<<l<<" "<<r<<endl; int m1 = l + (r-l+2)/3; int m2 = r - (r-l+2)/3; if(sim(m1) < sim(m2)){ r = m2; }else{ l = m1; } } int rs = 1e9; for(int i=-10;i<10;i++){ rs = min(rs, sim(l+i)); } cout<<rs<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...