#abc361c. C - Make Them Narrow
C - Make Them Narrow
Score : points
问题陈述
给定一个长度为 的序列 。 从 中自由选择恰好 个元素并移除它们,然后将剩余的元素按照原始顺序连接起来,形成一个新的序列 。 找到这个的最小可能值: 的最大值减去 的最小值。
以上为大语言模型 kimi 翻译,仅供参考。
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:
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