#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
vector<string>ans;
signed main(){
int n,p,q;
cin>>n>>p>>q;
p=min(p,n);
q=min(q,n);
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
a.pb(0);
int lo=1,hi=1e9;
while(hi>=lo){
int mid=(hi+lo)/2;
vector< vector<int> > dp(p+2,vector<int>(q+2,-1));
bool u=0;
for(int i=p;i>=0;i--){
for(int j=q;j>=0;j--){
if(i==p and j==q)continue;
int h=dp[i][j+1]+1;
int x=a[h];
while(h+1 <n and a[h+1 ]-x<= 2*mid){
h++;
}
dp[i][j]=max(dp[i][j],h);
h=dp[i+1][j]+1;
x=a[h];
while(h+1 <n and a[h+1 ]-x<=mid){
h++;
}
dp[i][j]=max(dp[i][j],h);
if(dp[i][j]==n-1)u=1;
}
}
if(u)hi=mid-1;
else lo=mid+1;
}
cout<<lo+1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |