Danny !
Practice
3.1 (20 votes)
Binary search
Easy
Searching
Problem
91% Success 5736 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 :

                                                                      enter image description here

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 :

  1. For each pair \((i,j)\), where \( 1 \le i < j \le N \) store in a list \(|A[i]-A[j]|\)

  2. Sort this list in non-decreasing order

  3. Print the \(K^{th}\) 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 \(i^{th}\) integer denotes \(A[i]\).

Output Format :

Print the required answer on a single line.

Constraints :

\( 2 \le N \le 200,000 \)

\( 1 \le A[i] \le 10^9 \) , where \( 1 \le i \le N \)

\( 1 \le K \le (N \times (N-1))/2 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
58 votes
Tags:
AlgorithmsEasyMonthly-ContestReady
Points:30
29 votes
Tags:
C++Basic ProgrammingBit ManipulationBasics of Bit ManipulationAlgorithmsBinary Search
Points:30
23 votes
Tags:
AlgorithmsMedium