Campsites Along the Trail
A long-distance trail has been surveyed, and n possible campsite markers have been staked into the
ground at distinct integer mile positions along the trail. The trail is a straight line, so a marker
is fully described by its mile position.
A hiking club is bringing k groups on a trip. Each group needs its own marker to camp at, and no
marker may host more than one group. The groups want to spread out as much as possible: among all
ways of choosing k of the n markers, they want the one that makes the smallest distance between
any two chosen markers as large as possible.
Given the positions of the markers, find this largest possible value of "the smallest distance between any two chosen markers".
Input
The first line contains two integers n and k (2 ≤ k ≤ n ≤ 2·10^5) — the number of surveyed
markers and the number of groups.
The second line contains n distinct integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ 10^9) — the mile
positions of the markers, in no particular order.
Output
Print a single integer: the maximum, over all ways to choose k of the n markers, of the minimum
distance between any two chosen markers.
Notes
In the first example, the markers (sorted) sit at miles 1, 2, 4, 8, 9. Choosing miles 1, 4, and 8 gives pairwise gaps of 3 and 4 (and 7 between the outermost pair), so the smallest gap among the chosen sites is 3 — no choice of 3 markers does better.
In the second example k equals n, so every marker must be used; the answer is simply the smallest
gap between consecutive markers once they are sorted (miles 1, 5, 10 give gaps 4 and 5, so the
answer is 4).