PDP-25 (2013) - Camp senior - 1 (kdiff)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

Problem

Let there be a sequence consisting of N distinct (in pairs) integers x_1, x_2, ... x_N. Let A be the multiset composed of all non-negative differences of pairs of elements in the sequence:

A = \{ x_i - x_j | i \ne j \;\;\text{ και }\;\; x_i > x_j \}

Let K be a natural number. Find the K-th smallest element of the multiset A.

Input

The input will consist of two lines. The first line will contain two natural numbers N and K, separated by a single space. The second line will contain N integers x_1, x_2, ... x_N, separated in pairs by single spaces.

Output

The output should consist of a single line containing only one natural number: the K-th smallest element of the multiset A.

Constraints

1 \le N \le 300.000
1 \le K \le N (N-1) / 2
-1.000.000.000 \le x_i \le 1.000.000.000
Execution time limit: 1 sec.
Memory limit: 64 MB.
Attention: The number K may be larger than 2^32.

Examples of Input - Output
1st

STDIN (kdiff.in)

10 1
1 2 5 -3 7 4 -6 8 0 3

STDOUT (kdiff.out)

1
2nd

STDIN (kdiff.in)

6 11
1 2 3 4 5 6

STDOUT (kdiff.out)

3

Explanation of the Examples: In the first example, we are asked for the minimum difference between elements of the sequence. This is 1 = 5 - (4). In the second example, the 11th smallest difference is requested. The multiset A contains the following elements:

\displaystyle \begin{array}{ccccc}
2-1 = 1, &3-1 = 2, &4-1 = 3, &5-1 = 4, &6-1 = 5, \\
&3-2 = 1, &4-2 = 2, &5-2 = 3, &6-2 = 4, \\
&&4-3 = 1, &5-3 = 2, &6-3 = 3, \\
&&&5-4 = 1, &6-4 = 2, \\
&&&&6-5 = 1.
\end{array}

So, Α = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5 }.
Therefore, the 5th largest element of it is (the underlined) 3.


Comments

There are no comments at the moment.