[ABC361C] 极差最小化移除 (Make Them Narrow)
Score : points
Problem Statement
You are given a sequence of length .
Freely choose exactly elements from and remove them, then concatenate the remaining elements in their original order to form a new sequence .
Find the minimum possible value of this: the maximum value of minus the minimum value of .
Constraints
-
All inputs are integers.
-
-
Input
The input is given from Standard Input in the following format:
$N$ $K$
$A_1$ $A_2$ $\dots$ $A_N$
Output
Print the answer as an integer.
Sample Input 1
5 2
3 1 5 4 9
Sample Output 1
2
Consider removing exactly two elements from .
- For example, if you remove the 2nd element and the 5th element , the resulting sequence is . In this case, the maximum value of is and the minimum value is , so (maximum value of ) (minimum value of ) , which is the minimum possible value.
Sample Input 2
6 5
1 1 1 1 1 1
Sample Output 2
0
Sample Input 3
8 3
31 43 26 6 18 36 22 13
Sample Output 3
18