Submission #159660

# Submission time Handle Problem Language Result Execution time Memory
159660 2019-10-23T18:41:43 Z theknife2001 Simfonija (COCI19_simfonija) C++17
44 / 110
52 ms 3064 KB
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N=1e5+55;
int a[N];
int b[N];
int x[N];
int n,k;

ll solve(int pos)
{
	for(int i=0;i<n;i++)
	a[i]=x[i];
	int i=0,j=n-1;
	int K=k;
	
	while(K--)
	{
		if(abs(a[i]-a[pos])>abs(a[j]-a[pos]))
		a[i]=a[pos],i++;
		else
		a[j]=a[pos],j--;
	}
	ll ans=0;
	for(;i<=j;i++)
		ans+=abs(a[i]-a[pos]);
	return ans;
}
		
		

int main()
{
  	ios::sync_with_stdio(false);
	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++)
	x[i]=a[i]-b[i];
	sort(x,x+n);
	cout<<min(solve(n/2),solve(n/2+1))<<endl;
	
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2936 KB Output is correct
2 Correct 37 ms 3024 KB Output is correct
3 Correct 34 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3064 KB Output is correct
2 Correct 36 ms 2972 KB Output is correct
3 Correct 33 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 2940 KB Output is correct
2 Correct 36 ms 2932 KB Output is correct
3 Correct 33 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 2296 KB Output is correct
2 Correct 43 ms 2896 KB Output is correct
3 Incorrect 34 ms 2936 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2936 KB Output is correct
2 Incorrect 34 ms 2936 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2936 KB Output isn't correct
2 Halted 0 ms 0 KB -