#K6716. Maximum Books Purchase
Maximum Books Purchase
Maximum Books Purchase
You are given a number of test cases. In each test case, you are given an integer N representing the number of books and an integer B representing the budget. You are also given a list of N integers representing the prices of the books.
Your task is to determine the maximum number of books that can be purchased without exceeding the budget B. You can buy the books in any order, but the optimal strategy is to buy the cheapest books first.
This can be formalized as finding the maximum integer k such that:
\[ \sum_{i=1}^{k} p_i \le B, \]where \(p_i\) are the book prices sorted in ascending order.
inputFormat
The input is read from standard input and has the following format:
T N1 B1 price1,1 price1,2 ... price1,N1 N2 B2 price2,1 price2,2 ... price2,N2 ...
Here, T is the number of test cases. For each test case, the first line contains two integers N and B where N is the number of books, and B is the available budget. The next line contains N space-separated integers representing the prices of the books.
outputFormat
For each test case, output a single line containing one integer: the maximum number of books that can be bought without exceeding the budget.
## sample2
5 50
15 20 10 30 25
3 30
20 10 40
3
2
</p>