


The initial score is 0.
Each box can be used at most once.
The boxes can be used in any order.
You don’t have to remove all the boxes.
The first line of input contains an integer ‘T’, denoting the number of test cases. The test cases follow.
The first line contains two integers ‘N’, and ‘power’, which denotes the number of elements in the array ‘gainPower’, and the initial power you have.
The second line contains N integers denoting the elements of the array ‘gainPower’.
For each test case, print the maximum score you can have after choosing any number of boxes and performing any of the two operations from the boxes chosen.
Print the output of the test case in a separate line.
You are not required to print the expected output, it has already been taken care of. Just implement the function.
1 <= T <= 50
1 <= N <= 10^4
1 <= gainPower[i], power <= 10^4
Where ’T’ is the number of test cases, N denotes the number of elements in the array ‘gainPower’,gainPower[i] denotes the power associated with the box at index ‘i’, and power denotes the initial power you have.
Time Limit: 1 sec
The idea is to sort the given array ‘gainPower’ and then use the two-pointer approach. Use two pointers ‘i’ and ‘j’ - one at the beginning and the other at the end of the array ‘gainPower’.
If the current power is greater than the power of the ith box, then increase the score by 1, subtract the power of the ith box from the current power and remove the box from the set. Otherwise, if the score is greater than or equal to 1, add the power of the jth box from the current power.
Algorithm: