답안 #200006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200006 2020-02-04T18:04:35 Z KLPP Simfonija (COCI19_simfonija) C++14
77 / 110
115 ms 4344 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/2+i];
		right-=d[k/2+i];
		right+=d[k+i];
		ans=min(ans,right-left+d[k/2]*(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 4088 KB Output is correct
2 Correct 110 ms 4088 KB Output is correct
3 Correct 108 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 4088 KB Output is correct
2 Correct 108 ms 4088 KB Output is correct
3 Correct 108 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 4216 KB Output is correct
2 Correct 107 ms 4088 KB Output is correct
3 Correct 108 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 4068 KB Output is correct
2 Correct 114 ms 4092 KB Output is correct
3 Correct 112 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 4088 KB Output is correct
2 Incorrect 108 ms 4088 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 4092 KB Output is correct
2 Correct 107 ms 4088 KB Output is correct
3 Correct 115 ms 4264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 4088 KB Output is correct
2 Incorrect 114 ms 4128 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 4216 KB Output is correct
2 Correct 109 ms 4244 KB Output is correct
3 Correct 114 ms 4088 KB Output is correct