제출 #1252708

#제출 시각아이디문제언어결과실행 시간메모리
1252708ilhan_arda구경하기 (JOI13_watching)C++20
50 / 100
1096 ms31924 KiB
//~ #pragma GCC optimize("O3,unroll-loops")
//~ #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
const int inf  = INT_MAX;
const int mod  = 1e9+7;

int n, p, q;
int a[2005], dp[2005][2005];
//~ inline int f(int ind, int p){
	//~ if(ind > n) return 0;
	//~ if(dp[ind][p] != -1) return dp[ind][p];
	//~ //kucuk
	//~ int t1 = inf, t2 = inf;
	//~ if(p){
		//~ int ind2 = upper_bound(a+1, a+n+1, a[ind]+w-1) - a;
		//~ t1 = f(ind2, p-1);
	//~ }
	//~ int ind2 = upper_bound(a+1, a+n+1, a[ind]+w*2-1) - a;
	//~ if(a[ind] + w*2 - 1 >= a[n])return true;
	//~ t2 = f(ind2, p)+1;
	//~ return dp[ind][p] = min(t1, t2);
//~ }
bool check(int w){
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<=p;i++){
		dp[n+1][i] = 0;
	}
	for(int i=n;i>=1;i--){
		for(int j=0;j<=p;j++){
			int t1 = inf, t2 = inf;
			if(j){
				int ind2 = upper_bound(a+1, a+n+1, a[i]+w-1) - a;
				t1 = dp[ind2][j-1];
			}
			int ind2 = upper_bound(a+1, a+n+1, a[i]+2*w-1) - a;
			t2 = dp[ind2][j]+1;
			dp[i][j] = min(t1, t2);
		}
	}
	if(dp[1][p]<=q)return true;
	else return false;
}
int32_t main(){
	fast;
	cin>>n>>p>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1, a+n+1);

	if(p + q >= n){
		cout<<1<<endl;
		return 0;
	}
	int l = 1, r = 1e9;
	while(l<=r){
		int m = (l+r)/2;
		if(check(m)){
			 r = m-1;
		}
		else l = m+1;
	}
	cout<<l<<endl;
}






//https://usaco.org/current/current/index.php?page=viewproblem2&cpid=282 bunu coz




//~ 10 15 19 33 53 66 66 68 75 83 83 93 99




#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...