제출 #468556

#제출 시각아이디문제언어결과실행 시간메모리
468556mychecksedad구경하기 (JOI13_watching)C++17
100 / 100
319 ms16060 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 2010, MX = 1e9;

int n, p, q, arr[N], dp[N][N], go[N][2]; // min_q, max_pos_p, max_pos_j
bool check(int w){
	int a = 1, b = 1;
	for(int i = 1; i <= n; i++){
		while(a < i && arr[a] + w <= arr[i]) a++;
		while(b < i && arr[b] + 2*w <= arr[i]) b++;
		go[i][0] = a - 1, go[i][1] = b - 1;
	}
	int res = MX;
	for(int i = 0; i <= p; i++) dp[0][i] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= p; j++){
			dp[i][j] = MX;
			if(j>0) dp[i][j] = min(dp[i][j], dp[go[i][0]][j - 1]);	
			dp[i][j] = min(dp[i][j], dp[go[i][1]][j] + 1);	
			if(i==n) res = min(res, dp[i][j]);	
			// cout << dp[i][j] << ' ';
		}
		// cout << '\n';
	}
	return (res <= q); 
}


int main(){
	cin >> n >> p >> q;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	if(p + q >= n){
		cout << 1;
		return 0;
	}
	sort(arr+1, arr+n+1);
	int l = 1, h = MX, ans = MX;
	while(l <= h){
		int mid = ((l+h)>>1);
		if(check(mid)){
			ans = min(ans, mid);
			h = mid - 1;
		}else
			l = mid + 1;
	}
	cout << ans;

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...