#K62177. Maximum Purchasable Books
Maximum Purchasable Books
Maximum Purchasable Books
You are given the prices of N books and a budget B. You are allowed to apply a discount on exactly one book such that its price becomes \(\lfloor \frac{price}{2} \rfloor\). Without exceeding the budget, you need to determine the maximum number of books you can purchase, taking full advantage of the discount on the optimal book.
Explanation: For each test case, you have two numbers: N (the number of books) and B (your budget). The next line provides N integers representing the price of each book. You may choose one book to apply the discount; its cost will then become \(\lfloor \frac{price}{2} \rfloor\). After applying the discount to one book, purchase books in increasing order of price until your budget is exhausted. You must determine, over all choices of which book to discount, the maximum number of books that you can buy.
Note: The discount can be applied to any one book and the discount only applies once per test case.
inputFormat
The input begins with an integer \(T\) representing the number of test cases. Each test case is described as follows:
- The first line contains two integers \(N\) and \(B\), where \(N\) is the number of books and \(B\) is the available budget.
- The second line contains \(N\) integers, each representing the price of a book.
All input values are provided via standard input.
outputFormat
For each test case, output a single line containing one integer: the maximum number of books that can be purchased without exceeding the budget, considering the optimal use of the discount. Output the results via standard output.
## sample2
5 100
20 50 30 40 90
4 80
50 70 80 90
3
1
</p>