Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/saralash-k-ta-yaqin-sonlar

k closest numbers

Medium 1000 ms 128 MB 47%
Share

$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.

Numbers on the number line; the k closest to each other are in brackets, the distance between the outer ones is highlighted

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

Sign in to submit a solution

Signing up is free and takes a minute.