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 <iostream>
#include <cmath>
#include<vector>
#include <algorithm>
#include <utility>
#include<stack>
#include<queue>
#include<map>
#include <fstream>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
long long a[100010],b[100010],d[100010];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
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++ ) d[i] = a[i]-b[i];
sort( d,d+n );
int neg=0;
for( int i=0;i<n;i++ ){
if( d[i] <= 0 ) neg++;
}
long long add;
if( neg > n-neg ){
add= abs( d[(n-1)/2] );
}
else add = -abs( d[ (n-1)/2 ] );
for( int i=0;i<n;i++ ){
a[i]+=add;
d[i] = abs( a[i] -b[i] );
}
sort( d,d+n, greater<long long>() );
long long sum=0;
for( int i=k;i<n;i++ ) sum+=d[i];
cout <<sum <<endl;
return 0;
}
# | 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... |