#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define rev2(i,a,b,c) for (int i=a;i>=b;i-=c)
#define bit(i,j) ((i>>j)&1)
#define pii pair<int,int>
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define ll long long
#define Fi first
#define Se second
#define on(n) __builtin_popcountll(n)
#define ld long double
#define __log2(x) 31-__builtin_clz(x)
#define Mask(x) (1LL<<x)
#define ALL(v) v.begin(),v.end()
const int MAXN=2e3+5;
const int mod=998244353;
int dp[MAXN][MAXN],n,p,q,x[MAXN];
bool check(int w){
// dp[i][j] the minimum number of large camera needed to be use for the first i event
// and use j small camera
// at event i 2 cases can happen
// case 1 use the small camera <=> dp[i'][j-1] with i' is the largest such that a[i]-a[i']>=w
// case 2 use the large camera <=> dp[i'][j-1] with i' is the largest such that a[i]-a[i']>=2*w
int smallL=-1,largeL=-1;
memset(dp,0x3f,sizeof(dp));
rep(j,0,p) dp[0][j]=0;
rep(i,1,n){
while(smallL+1<i&&x[i]-x[smallL+1]>=w) smallL++;
while(largeL+1<i&&x[i]-x[largeL+1]>=2*w) largeL++;
rep(j,0,p){
dp[i][j]=dp[largeL][j]+1;
if (j>0) dp[i][j]=min(dp[i][j],dp[smallL][j-1]);
}
}
return (dp[n][p]<=q);
}
void solution(){
cin >> n >> p >> q;
p=min(p,n);
q=min(q,n);
x[0]=-1e9;
rep(i,1,n) cin >> x[i];
sort(x+1,x+1+n);
int l=1,r=1e9;
while(l<r){
int mid=(l+r)/2;
if (check(mid)) r=mid;
else l=mid+1;
}
cout << l;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test=1;
while(test--)
solution();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |