4176. 愤怒的牛
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 100010;
int n, m;
int d[N];
bool check(LL mid)
{
int cnt = 1;
for (int i = 1, j = 0; i < n; i ++)//i代表当前这头牛,j代表前一头牛
if (d[i] - d[j] >= mid) cnt ++, j = i;
return cnt >= m;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; i ++) cin >> d[i];
sort(d, d + n);
LL l = 1, r = 1e9;
while (l < r)
{
LL mid = l + r + 1 >> 1;
if (check(mid)) l = mid;
else r = mid - 1;
}
cout << l << '\n';
return 0;
}