# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703926 | chenyan | Simfonija (COCI19_simfonija) | C++17 | 28 ms | 2676 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>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 100010
int dp[N],a[N],b[N],p[N];
vector<int>v;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,i,k,j;
cin>>n>>k;
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<=n;i++)cin>>b[i];
for(i=1;i<=n;i++)a[i]=b[i]-a[i],p[i]=a[i]+p[i-1];
sort(a+1,a+n+1);
int l=0,r=n-k,ans=1e18;
for(i=1;i<=n;i++){
while(l<i&&r<n&&a[r]-a[i]<a[i]-a[l+1])l++,r++;
ans=min(ans,(p[r]-p[i])-a[i]*(r-i)+a[i]*(i-l)-(p[i]-p[l]));
}
cout<<ans<<'\n';
}
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... |