Submission #125928

#TimeUsernameProblemLanguageResultExecution timeMemory
125928OptxPrimeSimfonija (COCI19_simfonija)C++11
44 / 110
46 ms4216 KiB
#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 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...