C. 劳动节

    Type: Default 1000ms 256MiB

劳动节

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

在另一个世界,今天是劳动节。

在 光头强 的花园里种了 NN 棵树。第ii棵树(1iN1 \leq i \leq N)的高度为hih_i米。

光头强决定从这些树中选出KK棵树,进行修剪。为了使风景更加美丽,修剪的树的高度应该尽可能接近。

具体来说,设最高装饰树的高度为 hmaxh_{max} 米,最矮装饰树的高度为 hminh_{min} 米。hmaxhminh_{max}-h_{min}值越小,越好。hmaxhminh_{max}-h_{min}的最小可能值是多少?

输入

第一行2个整数NN表示总的树的数目,KK表示选出的树的数目。

接下来NN行分别表示不同的树的高度

输出

输出hmaxhminh_{max}-h_{min}的最小可能值

5 3
10
15
11
14
12
2

样例解释

如果我们修剪第一、第三和第五棵树,hmaxh_{max} = 12,hminh_{min} = 10,因此 hmaxhminh_{max} - h_{min} = 2。这是最优的。

5 3
5
7
5
7
7
0

样例解释

如果我们修剪第二、第四和第五棵树,hmaxh_{max} = 7,hminh_{min} = 7,因此 hmaxh_{max} - hminh_{min} = 0。这是最优的。

提示

2K<N105 2 \leq K < N \leq 10^5

1hi1091 \leq h_i \leq 10^9

hi h_i 是整数

粒子2024年11月上半月月赛

Not Attended
Status
Done
Rule
IOI
Problem
4
Start at
2024-10-27 0:00
End at
2024-11-10 0:00
Duration
2 hour(s)
Host
Partic.
16