Submission #100343

#TimeUsernameProblemLanguageResultExecution timeMemory
100343tpoppoSimfonija (COCI19_simfonija)C++14
55 / 110
135 ms2812 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; v.reserve(n); for(int i=0;i<n;i++) v.push_back( abs(a[i]-b[i] + x)); nth_element(v.begin(),v.begin() + n - k,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); #ifdef TPOPPO freopen("in.txt","r",stdin); #endif // TPOPPO 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; while(r - l > 5){ //cout<<l<<" "<<r<<endl; int m1 = l + (r-l)/3; int m2 = r - (r-l)/3; //cout<<dx[l]<<" "<<dx[r]<<" => "<<dx[m1]<<": " << sim(dx[m2]) - sim(dx[m1]) <<endl; if(sim(m1) < sim(m2)){ r = m2; }else{ l = m1; } } int rs = 1e16; for(int i=l;i<=r;i++){ //cout<<i<<": "<<sim(i)<<'\n'; rs = min(sim(i),rs); } 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...