#C2777. Maximize Items Purchase
Maximize Items Purchase
Maximize Items Purchase
You are given a list of prices for different items and a total budget. Your task is to determine the maximum number of items you can purchase without exceeding the budget. Each item can be bought at most once and you must select items in such a way that the sum of their prices does not exceed the budget.
Mathematically, if you have prices \(p_1, p_2, \dots, p_n\) and a budget \(B\), you need to find the maximum \(k\) such that there exists a subset of \(k\) items with \(\sum_{i=1}^{k} p_i \le B\).
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains two integers \(n\) and \(B\) where \(n\) is the number of items and \(B\) is the budget. The second line contains \(n\) space-separated integers representing the prices of each item.
\(1 \leq n \leq 10^5\) and each price is a positive integer.
outputFormat
Output a single integer representing the maximum number of items that can be purchased without exceeding the budget. The output should be written to standard output (stdout).
## sample5 7
1 3 2 4 1
4
</p>