Problem of the day
Suppose there are 3 fruits with costs 1, 2, 3 and nutrition 2, 2, 3 units respectively. Ninja has 3 units of money. Then, the ninja can take fruits with costs 1 and 2, having the maximum nutritional value of 4 units for a cost of 3 units.
The first line contains ‘T,’ denoting the number of test cases.
The first line of each test case contains two space-separated integers, ‘M’ and ‘N’, denoting the amount of money ninja has and the total number of fruits.
The next ‘N’ line contains two space-separated integers, ‘X’ and ‘Y’, denoting each fruit's cost and nutrition value.
Print two space-separated integers the maximum amount of nutrition Ninja can get and the total cost to get maximum nutrition.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= N <= 1000
1 < = M <=1000
0 < = X <= 1000
0 < = Y <= 1000
Time Limit: 1 sec
2
9 4
1 2
2 3
4 5
5 7
6 3
7 4
9 2
11 12
12 8
0 0
For the first test case:-
The ninja can select the fruits at indices ( 0 - based ) 0, 1, and 3, which constitutes 12 units of nutrition and 8 units of cost.
For the second test case:-
The Ninja can not buy any of these fruits so he will have his nutrition as 0 and cost also 0 as well
2
50 10
12 3
15 8
16 9
16 6
10 2
21 9
18 4
12 4
17 8
18 9
50 10
13 8
19 10
16 8
12 9
10 2
12 8
13 5
15 5
11 7
16 2
26 49
32 48