제출 #1137

#제출 시각아이디문제언어결과실행 시간메모리
1137kriii구경하기 (JOI13_watching)C++98
100 / 100
248 ms17032 KiB
#include <stdio.h>
#include <algorithm>
using namespace std;

int N,P,Q,A[2020];
int D[2020][2020];

bool chk(int w)
{
	if (w <= 0) return false;

	int i,j=1,k=1,l;
	for (i=1;i<=N;i++){
		while (A[i] - A[j] >= w) j++;
		while (A[i] - A[k] >= w * 2) k++;
		for (l=0;l<=Q;l++) D[i][l] = D[j-1][l] + 1;
		for (l=0;l<=Q;l++){
			if (D[i][l+1] > D[k-1][l])
				D[i][l+1] = D[k-1][l];
		}
	}

	for (l=0;l<=Q;l++) if (D[N][l] <= P) return true;
	return false;
}

int main()
{
	int i;

	scanf ("%d %d %d",&N,&P,&Q);
	for (i=1;i<=N;i++) scanf ("%d",&A[i]);
	sort(A+1,A+1+N);

	if (N <= P + Q) printf ("1");
	else{
		int l = 1, r = 1000000000, m;
		while (l < r){
			m = (l + r) / 2;
			if (chk(m)) r = m - 1;
			else l = m + 1;
		}
		while (chk(m)) m--;
		while (!chk(m)) m++;
		printf ("%d",m);
	}

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