코드
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
static int n, c;
static int[] homePosition;
public static void main (String[] args) {
input();
System.out.println(func());
}
static void input() {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
c = sc.nextInt();
homePosition = new int[n];
for (int i = 0; i < n; ++i) {
homePosition[i] = sc.nextInt();
}
sc.close();
}
static int func() {
Arrays.sort(homePosition);
int left = 0;
int right = 1_000_000_000;
int result = -1;
while (right >= left) {
int mid = (left + right) / 2;
if (getInstallCount(mid) >= c) {
result = mid;
left = mid + 1;
} else {
right = mid - 1;
}
}
return result;
}
static int getInstallCount(int minDistance) {
int count = 1;
int lastPosition = homePosition[0];
for (int i = 1; i < homePosition.length; ++i) {
if (homePosition[i] - lastPosition >= minDistance) {
lastPosition = homePosition[i];
++count;
}
}
return count;
}
}