Processing math: 100%
Sorting the differences - MarisaOJ: Marisa Online Judge

Sorting the differences

Time limit: 1000 ms
Memory limit: 256 MB
Given an array A with n integer elements, rearrange all values of |Ai−Aj| in non decreasing order for all 1≤i<j≤n. Determine the value at the k-th position in the resulting sequence. ### Input - The first line consists of twos integer n,k. - The second line contains n integers Ai. ### Output - Print the k-th largest value. ### Constraints - 1≤n≤105. - 1≤k≤n×(n−1)2 - 1≤Ai≤109. ### Example Input: 5929478 Output: 6