ALGOR Contest: Round #3 (Weekly Sprint)
Problem D · 200 points ·
ICPC rules
~/algor $ cat contests/round-3/D
D. k closest numbers
1000 ms
128 MB
$n$ integers and a positive integer $k$ are given. Choose $k$ of them (at different positions) so that the difference between the largest and the smallest chosen number is as small as possible. Print this difference.
Input
The first line contains two positive integers: $n$ and $k$. The second line contains $n$ integers $a_{i}$.
Output
One integer — the smallest difference.
Note
$1 \le k \le n \le 2 \cdot 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$
Examples
Input #1
6 3 10 1 13 4 20 11
Output #1
3
Input #2
1 1 5
Output #2
0