#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const ll MAXN=2e3+5,INF=1e9,MOD=1e9+7;
ll n,m,i,j,k,p,a[MAXN],dp[MAXN][MAXN];
bool check(ll range){
for(ll i=1;i<=m;i++)
for(j=1;j<=k;j++) dp[i][j]=0;
dp[0][0]=1;
for(i=0;i<=m;i++){
for(j=0;j<=k;j++){
ll cur=a[dp[i][j]]+range;
ll nextsm=upper_bound(a+1,a+n+1,cur-1)-a,nextl=upper_bound(a+1,a+n+1,cur+range-1)-a;
dp[i][j+1]=nextl;
dp[i+1][j]=nextsm;
}
}
if(dp[m][k]>n) return true;
return false;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m>>k;
for(i=1;i<=n;i++) cin>>a[i];
sort(a+1,a+n+1);
if(m+k>=n){
cout<<1;
return 0;
}
ll l=1,r=INF,best=0;
while(l<r){
ll m=(l+r)/2;
if(check(m))
r=m-1,best=r;
else l=m+1;
}
cout<<best;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |