Submission #159661

# Submission time Handle Problem Language Result Execution time Memory
159661 2019-10-23T18:42:18 Z theknife2001 Simfonija (COCI19_simfonija) C++17
44 / 110
38 ms 1592 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 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1528 KB Output is correct
2 Correct 35 ms 1512 KB Output is correct
3 Correct 32 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1528 KB Output is correct
2 Correct 35 ms 1592 KB Output is correct
3 Correct 32 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1504 KB Output is correct
2 Correct 35 ms 1500 KB Output is correct
3 Correct 32 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 1528 KB Output is correct
2 Correct 32 ms 1528 KB Output is correct
3 Incorrect 33 ms 1528 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1528 KB Output is correct
2 Incorrect 33 ms 1524 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 1528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 1500 KB Output isn't correct
2 Halted 0 ms 0 KB -