#P1824. [USACO05FEB] 进击的奶牛 Aggressive Cows G

[USACO05FEB] 进击的奶牛 Aggressive Cows G

Description

Farmer John built a barn with nn stalls arranged on a straight line; the ii-th stall is at position xix_i. His mm cows are unhappy and often fight, so he wants to place them so that each cow is as far as possible from the others. In other words, he wants to maximize the minimum distance between any two cows.

Cows do not like this layout, and if multiple cows share a stall, they will fight. To prevent conflicts, each stall can hold at most one cow. Determine the largest possible value of the minimum distance between any two cows.

Input Format

The first line contains two integers nn and mm.

The next nn lines each contain one integer xix_i, representing the position of a stall.

Output Format

Output a single integer: the maximum possible minimum distance.

5 3
1
2
8
4
9
3

Hint

Sample Explanation: Place the cows at positions 11, 44, and 88; the minimum distance is 33. It is easy to prove that this minimum distance is already maximized.

Constraints: For 100%100\% of the testdata, 2n1052 \le n \le 10^5, 0xi1090 \le x_i \le 10^9, 2mn2 \le m \le n. The array xx is not guaranteed to be in nondecreasing order.

Translated by ChatGPT 5