#K76792. Maximizing Purchases Under Budget
Maximizing Purchases Under Budget
Maximizing Purchases Under Budget
You are given a list of item prices and a budget. Your task is to determine the maximum number of items you can purchase without exceeding the given budget. You may buy the items in any order. It is always optimal to purchase the cheapest items first. Formally, if the sorted prices are \(p_1 \le p_2 \le \dots \le p_n\), you must find the largest \(k\) such that \(\sum_{i=1}^{k} p_i \leq B\), where \(B\) is the budget.
If there are multiple test cases, solve each test case independently.
inputFormat
The first line of input contains a single integer \(T\) (\(1 \le T \le 10^4\)) which denotes the number of test cases. The description of the test cases follows.
For each test case, the first line contains two integers \(n\) and \(B\) (\(1 \le n \le 10^5\), \(1 \le B \le 10^9\)) where \(n\) is the number of items and \(B\) is the budget. The second line contains \(n\) space-separated positive integers representing the price of each item. It is guaranteed that all prices are positive integers.
Note: The input is to be read from standard input (stdin).
outputFormat
For each test case, output a single integer representing the maximum number of items that can be purchased without exceeding the budget. Each answer should be printed on a new line. The output should be written to standard output (stdout).
## sample1
5 10
1 12 5 111 200
2
</p>