相当于奶牛多了两头(奶牛数即n-m+2石头总数-移走石头数+2),一个在起点,一个在终点,房子多了两间,起点一间,终点一间,几乎就是一道题。
import java.util.Arrays;
import java.util.Scanner;
public class POJ_3258 {
static int l,n,m;
static int[] x=new int[50005];
static boolean C(int d){
int last=0;
for (int i = 1; i < m; i++) {
int crt=last+1;
while(crt<n+2&&x[crt]-x[last]<d){
crt++;
}
if(crt==n+2)return false;
last=crt;
}
return true;
}
static void solve(){
Arrays.sort(x);
int lb=0,ub=1000000009;
while(ub-lb>1){
int mid=(lb+ub)/2;
if(C(mid))lb=mid;
else ub=mid;
}
System.out.println(lb);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
l=sc.nextInt();
n=sc.nextInt();
m=sc.nextInt();
m=n-m+2;
Arrays.fill(x,1000000009);
x[0]=0;
for (int i = 1; i <= n; i++) {
x[i]=sc.nextInt();
}
x[n+1]=l;
solve();
}
}