Submission #159661

#TimeUsernameProblemLanguageResultExecution timeMemory
159661theknife2001Simfonija (COCI19_simfonija)C++17
44 / 110
38 ms1592 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N=1e5+55; int a[N]; int b[N]; int x[N]; int n,k; ll solve(int pos) { for(int i=0;i<n;i++) a[i]=x[i]; int i=0,j=n-1; int K=k; while(K--) { if(abs(a[i]-a[pos])>abs(a[j]-a[pos])) a[i]=a[pos],i++; else a[j]=a[pos],j--; } ll ans=0; for(;i<=j;i++) ans+=abs(a[i]-a[pos]); return ans; } int main() { 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]; for(int i=0;i<n;i++) x[i]=a[i]-b[i]; sort(x,x+n); cout<<min(solve(n/2),solve(n/2-1))<<endl; 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...