- paste
奶牛
- 2023-11-16 15:13:49 @
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N =1e6+5;
int n, m, a[N];
bool check(int x){
int st = a[0];
int cou = 1;
for(int i = 1; i < n; i++){
if(a[i] - st < x) continue;
st = a[i];
cou++;
}
return cou >= m;
}
void solve() {
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a, a+n);
int l = 0, r = 1e9;
int mid;
while(l < r){
mid = l + r + 1 >> 1;
if(check(mid)) l = mid;
else r = mid-1;
}
cout << l;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
12 8
1
3
6
11
18
27
38
41
56
73
92
113
*/
0 comments
No comments so far...