답안 #200007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200007 2020-02-04T18:12:45 Z KLPP Simfonija (COCI19_simfonija) C++14
110 / 110
127 ms 4088 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int n,k;
lld a[1000000];
lld b[1000000];
lld d[1000000];
int main() {
	cin>>n>>k;
	rep(i,0,n)cin>>a[i];
	rep(i,0,n)cin>>b[i];
	rep(i,0,n)d[i]=a[i]-b[i];
	sort(d,d+n);
	lld ans=1e16;
	lld left=0;
	lld right=0;
	k=n-k;
	if(k==0){
		cout<<0<<endl;
		return 0;
	}
	rep(i,0,k){
		if(2*i<k){
			left+=d[i];
		}else right+=d[i];
	}
	ans=min(ans,right-left+d[k/2]*(k%2));
	
	for(int i=0;k+i<n;i++){
		left-=d[i];
		left+=d[(k+1)/2+i];
		right-=d[(k+1)/2+i];
		right+=d[k+i];
		ans=min(ans,right-left+d[k/2+i+1]*(k%2));
	}
	cout<<ans<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 2680 KB Output is correct
2 Correct 110 ms 2684 KB Output is correct
3 Correct 104 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 2680 KB Output is correct
2 Correct 110 ms 2684 KB Output is correct
3 Correct 107 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 2624 KB Output is correct
2 Correct 111 ms 2672 KB Output is correct
3 Correct 127 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 2680 KB Output is correct
2 Correct 106 ms 4088 KB Output is correct
3 Correct 110 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 2808 KB Output is correct
2 Correct 112 ms 2680 KB Output is correct
3 Correct 114 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 2684 KB Output is correct
2 Correct 113 ms 2680 KB Output is correct
3 Correct 117 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 2680 KB Output is correct
2 Correct 114 ms 2680 KB Output is correct
3 Correct 116 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 2684 KB Output is correct
2 Correct 112 ms 2680 KB Output is correct
3 Correct 123 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 2680 KB Output is correct
2 Correct 110 ms 2680 KB Output is correct
3 Correct 113 ms 2680 KB Output is correct