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

~/algor $ cat problems/saralash-k-chi-kichik-farq

k-th smallest difference

Hard 1000 ms 128 MB 95%
Share

$n$ integers are given. For all $\frac{n(n-1)}{2}$ pairs ($i \lt j$) the differences $|a_{i} - a_{j}|$ are written down and sorted in increasing order (each of the equal differences takes a separate place). Find the $k$-th element of this list. For example, for $1, 6, 3, 10$ the differences are $2, 3, 4, 5, 7, 9$, and the fourth of them is $5$.

Numbers on the number line; the differences of all pairs are shown as arcs, the k-th smallest 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 $k$-th smallest difference.

Note

$2 \le n \le 3 \cdot 10^{4}$
$1 \le k \le \frac{n(n-1)}{2}$
$0 \le a_{i} \le 10^{9}$

Examples

Input #1
4 4
1 6 3 10
Output #1
5
Input #2
2 1
5 5
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.