Go Back
Shweta And Her Rakhi (100)

On the eve of Rakshabandhan, Shweta wants to buy a Rakhi for her brother. She visits a shop and finds that there are N Rakhis of different sizes. The shopkeeper tells her that the cost C of a Rakhi is directly proportional to its size. He also tells Shweta that the cost of all the Rakhis are distinct.
Shweta is finding it difficult to keep track of the cost of all the Rakhis. So she asks the shopkeeper to convert it into a reduced form, where the cost is reduced to the range 0 to N-1. The shopkeeper replaces the cost of cheapest Rakhi with 0, the next cheapest Rakhi with 1, and so on, the costliest Rakhi with N-1.
From this reduced cost list of Rakhis, Shweta asks the shopkeeper to give her the Kth Rakhi.
Find out what is the value of the Rakhi at Kth position in the reduced cost list.


The first line of input contains an integer T denoting the number of test cases.
For each test case, the first line contains 2 space-separated integers N & K.
The next line contains N space-separated elements, denoting the cost C of Rakhi.


For each test case, output the value of the Rakhi at Kth position of the reduced form, in a single line.


1<=T, N<=100

Copy Input

3 2
10 40 20
5 3
5 10 40 30 20


Case 1:
The cost of the cheapest Rakhi is 10 and that of costliest Rakhi is 40. Thus 10 is replaced by 0, 20 is replaced by 1 and 40 is replaced by 2. The reduced cost list is {0, 2, 1}. In this case, K=2. The number at 2nd position in this reduces list is 2.
Case 2:
Similarly, the reduced cost list for this case is {0, 1, 4, 3, 2}. Here K=3. The number at 3rd position in this array is 4.

September Queue
36 hour long contest

01:40 PM: Check your submission to see details about CE or RTE
12:28 PM: In Problem D, all the numbers are in single line for each test
Tips and Tricks for Python: Visit Here
Tips and Tricks for C++: Visit Here
Tips and Tricks for Java: Visit Here

Problem Tags

Supported by our Coding Partner