Problem
Let there be a sequence consisting of distinct (in pairs) integers , , . Let be the multiset composed of all non-negative differences of pairs of elements in the sequence:
Let be a natural number. Find the -th smallest element of the multiset .
Input
The input will consist of two lines. The first line will contain two natural numbers and , separated by a single space. The second line will contain integers , , , separated in pairs by single spaces.
Output
The output should consist of a single line containing only one natural number: the -th smallest element of the multiset .
Constraints
Execution time limit: 1 sec.
Memory limit: 64 MB.
Attention: The number may be larger than .
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 . In the second example, the th smallest difference is requested. The multiset contains the following elements:
So, Α = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5 }.
Therefore, the th largest element of it is (the underlined) .
Comments