

Ninja is assigned a task to deliver some boxes which contain different units having different weights. With the help of his truck, he will earn money on the basis of the number of units of boxes he will deliver by his truck. Ninja truck has some capacity on the number of boxes he can put on his truck.
So your task is to find a way so that ninja will choose boxes in a way that units will be maximum and he would be able to get more money you will be provided with an array of ‘BOX’
where BOX[i] = [countofBoxes, unitsperBox]:
countofBoxes is the number of boxes of type I.
unitsperBox is the number of units in each box of type I.
And an integer ‘K’ denoting the limit of boxes on the truck.
Input Format:
The first line of input contains a ‘T’ number of test cases.
The first line of each test case contains an integer ‘N’ and ‘K’ denoting the number of rows in array ‘BOX’ and the limit on boxes on the truck. Then, ‘N’ lines follow.
Each line contains two space-separated integers denoting the row values i.e count of boxes and units per box.
Output Format:
For each test case, print a single line containing the maximum number of units that Ninja can deliver.
The output of each test case will be printed in a separate line.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= N <= 1000
1 <= BOX[i] <= 1000
1 <= K <= 10 ^ 6
Where ‘T’ is the number of test cases, ‘N’ is the number of rows in 2-D array ‘BOX’, and ‘K’ is the limit on boxes on the truck.
Time Limit: 1 sec
2
3 3
1 1
2 5
1 3
2 1
2 5
3 4
13
5
Test Case 1:
As the limit on boxes is ‘3’ so we choose ‘2’ boxes each of ‘5’ units and ‘1’ boxes of ‘3’ units making our maximum number of units in the required number of boxes that is ‘13’.
Test Case 2:
As the limit on boxes is ‘1’ so we can choose only one box so we choose ‘1’ box containing ‘5’ units making our maximum number of units in the required number of boxes that is ‘5’.
1
4 4
3 5
2 10
1 15
2 4
40
Test Case 1:
As the limit on boxes is ‘4’ so we choose ‘1’ box of ‘15’ units and ‘2’ box of ‘10’ units each and ‘1’ box of ‘5’ unit making our maximum number of units in the required number of boxes that is ‘40’.
Can you think of using a 1-D array for storing each box weight?
The idea here is to store all boxes units separately in a 1-D array and now from that array, we can easily find the maximum value which can be formed using boxes satisfying given condition on the box.
O(N * log(N) ), where ‘N’ represents the total number of boxes present in the given ‘BOX’ array.
As we are sorting our array which takes O(N * log(N) ) all other loops will cost us time complexity as O(N) so overall complexity becomes O(N * log(N) ).
O(N ), where ‘N’ represents the total number of boxes present in the given ‘BOX’ array.
As we are using a 1-D array which takes space equal to no of boxes in each row present in the given ‘BOX’ array.