이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (int)(1000000007)
const int inf = 1e18;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n, k;
cin>>n>>k;
vector<int>Pre(n);
for(int i=0;i<n;i++){
cin>>Pre[i];
}
for(int i=0, a;i<n;i++){
cin>>a;
Pre[i]-=a;
}
sort(all(Pre));
int ans=inf;
for(int i=1;i<n;i++)
Pre[i]+=Pre[i-1];
for(int i=0, r=n-k-1, md=(n-k)/2;r<n;i++, r++, md++){
int val=Pre[md]-(md?Pre[md-1]:0);
int sum=(md-i+1)*val-(Pre[md]-(i?Pre[i-1]:0))+(r+1?Pre[r]:0)-Pre[md]-val*(r-(md+1)+1);
ans=min(ans, sum);
}
cout<<ans;
}
# | 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... |