题目描述 Description
yh拥有一条街道,街道上共有n间房子,每间房子的坐标为xi(yh的房子比较神奇,可能重叠)。
同时,yh有m个女朋友(这是事实),yh打算给每位女朋友分配一间房子。两个女朋友间的距离相隔越近,她们之间产生冲突的可能就越高。yh想尽可能的减小女朋友间的冲突,于是他打算让他的女朋友间的最小距离最大,你能帮yh找出这个最大值吗? 输入描述 Input Description
第一行两个整数,n,m,表示yh有n间房子,有m个女朋友
第二行为n个整数,xi,表示各间房子的坐标。 输出描述 Output Description
输出1行,表示yh女朋友间的最小距离的最大值 样例输入 Sample Input
5 3
1 2 8 4 9 样例输出 Sample Output
3 数据范围及提示 Data Size & Hint
对于30%的数据,n<=100,m<=n,0<=xi<=10000;
对于100%的数据,n<=100000 ,m<=n,0 <= xi <= 1000000000
include
include
using namespace std; int n,m,l,r,mid; long long x[100005]; bool check(int mid) { int cnt=1; int last=1; for(int i=2;i<=n;i++) { if(x[i]-x[last]>mid) { cnt++; last=i; } } if(cnt