


The complexity of each task is pairwise distinct.
N a b
5 3 2
C: 5 19 2 62 1
Here ‘X’ can be 2,3,4 as 3 tasks have greater complexity that will be assigned to Ninja and the remaining two will be assigned to NInja’s friend.
So the answer is 3.
The first line contains a single integer ‘T’ representing the number of test cases. Then test cases follow:
The first line contains three integers ‘N’, ‘A’, and ‘B’ representing the total number of tasks, number of tasks that will ninja solve, and the number of tasks that ninja’s friend will solve.
The second line contains ‘N’ space-separated elements denoting the complexity of each task.
For each test case, return an integer denoting the number of ways to choose ‘X’ as described in the problem.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
2 <= N <= 10^5
1 <= A,B <= N
1 <= C[i] <= 10^9
Time Limit: 1 sec
Firstly, if the sum of ‘A’, ‘B’ > ‘N’ then simply we will return 0 as it is not possible to assign more tasks than ‘N’.
Then, we need to find all those ‘X’ on which atleast ‘B’ number of tasks have complexity less than ‘X’ and atleast ‘A’ number of tasks have complexity greater than ‘X’.
Now, If ‘A’ + ‘B’ <= ‘N’, then we will first sort the array and then select first ‘B’ number of tasks for Ninja’s friend and the last ‘A’ tasks are for Ninja. So we will take the difference between C[B-1] and C[N-A] as on all these values C[B-1], C[B-1]+1, C[B-1]+2, …….., C[N-A]-1 of ‘X’ atleast ‘B’ tasks will be less or equal complexity which will be assigned to the Ninja's friend and ‘A’ tasks will have greater complexity than ‘X’ which will be assigned to Ninja.