#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,m;
long long x[200005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<n; i++) {
cin >> x[i];
}
sort(x,x+n);
long long st,en;
long long res=0;
st=1;
en=x[n-1]-x[0];
while(st<=en) {
long long cnt=1;
long long mid=(st+en)/2;
long long cur_idx=x[0];
for(int i=1; i<n; i++) {
if(mid<=x[i]-cur_idx) {
cnt++;
cur_idx=x[i];
}
}
if(cnt>=m) {
res=mid;
st=mid+1;
} else{
en=mid-1;
}
}
cout << res;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: