Submission #100268

#TimeUsernameProblemLanguageResultExecution timeMemory
100268amiSimfonija (COCI19_simfonija)C++14
110 / 110
49 ms4344 KiB
#include <bits/stdc++.h> #define sz(c) int(c.size()) #define rep(i,a,b) for (int i=a; i<(b); ++i) #define per(i,a,b) for (int i=(b)-1; i>=(a); --i) using namespace std; using ll = long long; ll const INF=1e18; int const MAXN=110000; int N,K; int A[MAXN]; int B[MAXN]; ll d[MAXN]; ll prSum[MAXN]; ll sum(int l,int r) { return prSum[r]-prSum[l]; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cout<<fixed<<setprecision(10); cin>>N>>K; rep(i,0,N) cin>>A[i]; rep(i,0,N) cin>>B[i]; rep(i,0,N) d[i]=A[i]-B[i]; sort(d,d+N); prSum[0]=0; rep(i,0,N) prSum[i+1]=prSum[i]+d[i]; int n=N-K; ll res=INF; rep(i,n/2,N-(n-1)/2) { ll leftSum=d[i]*(n/2) - sum(i-n/2,i); ll rightSum=sum(i+1,(i+1)+(n-1)/2) - d[i]*((n-1)/2); res=min(res,leftSum+rightSum); } cout<<res<<"\n"; }
#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...