Stevie : "Integer sequences, that's my main activity off the pitch. Let's play with them". Great defenders are an asset to any team, just like this guy :
You are given a sequence of positive integers in the form of an array A of size N and a number K. Now, you need to perform a certain procedure over this sequence that is as follows :
For each pair (i,j), where 1≤i<j≤N store in a list |A[i]−A[j]|
Sort this list in non-decreasing order
Print the Kth element of this list (1 indexed)
Note that X denotes the absolute value of any integer X
You need to perform the following procedure and print to output whatever it leads to. Can you do it ?
input Format :
The first line contains 2 space separated integers N and K respectively. The next line contains N space separated integers, where the ith integer denotes A[i].
Output Format :
Print the required answer on a single line.
Constraints :
2≤N≤200,000
1≤A[i]≤109 , where 1≤i≤N
1≤K≤(N×(N−1))/2
The List we create after sorting it is :
[1,2,2,3,3,4,4,5,6,8]
As you may observe the 4th element of this 3. So, clearly the answer is 3.