cswork / OAOpen practice workspace

AmazonOA #167

Find Min Max Difference

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersStacks & HeapsIn-place Arrays

Keep n−k of the original elements, sort the kept elements, and take their maximum adjacent difference; minimize that value. When only 1 element is kept, this site's convention is that the maximum adjacent difference is 0. The source text is truncated; the objective of this problem was recovered from its complete example explanation, and it is not to minimize the maximum minus the minimum of the whole range.

Input

The first line contains n k, and the second line contains n numbers. This site sets 1≤n≤200000, 0≤k<n, and values in −10^9..10^9.

Output

Output a single integer answer.

Example 1

Input:

5 2
1 4 3 6 5

Output:

1

Example 2

Input:

3 2
1 10 20

Output:

0

Example 3

Input:

4 0
1 4 8 9

Output:

4

Example notes

Example 1: keep 3, 4, 5, for a maximum adjacent difference of 1. Example 2: only one element is kept, so the answer is 0. Example 3: no number can be deleted, the adjacent differences are 3, 4, 1, so the answer is 4.

Editorial

Loading solution…