#include <stdio.h>
#include <stdlib.h>
int compare(const void *a, const void *b) {
if(*(long long *)a >*(long long *)b) return 1;
else return -1;
}
long long num[200001];
int main() {
int n,c;
scanf("%d %d",&n, &c);
for(int i=0; i<n; i++) {
scanf("%lld",&num[i]);
}
qsort(num,n,sizeof(long long),compare);
//최소 간격
long long low=1;
long long res=0;
//최대 간격
long long high=num[n-1]-num[0];
//이분탐색
while(low<=high) {
long long mid=(low+high)/2;
//공유기 갯수
int cnt = 1;
long long start=num[0];
for(int i=1; i<n; i++) {
//간격이 mid보다 클때
if(num[i]-start>=mid) {
cnt++;
start=num[i];
}
}
//공유기 수가 같거나 많을때
if(cnt>=c) {
res=mid;
low=mid+1;
} else {
high = mid -1;
}
}
printf("%lld",res);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: