#K44932. Budget Shopping
Budget Shopping
Budget Shopping
You are given a list of integers representing the prices of various items and an integer representing your budget. Your task is to determine the maximum number of items you can purchase without exceeding your budget and the total cost spent on these items. You should adopt a greedy strategy by first sorting the list of prices in non-decreasing order and then selecting items sequentially until no further item can be bought without exceeding the budget.
Mathematically, if you have prices (p_1, p_2, \ldots, p_n) sorted such that (p_1 \le p_2 \le \ldots \le p_n), then you must choose the largest (k) such that (\sum_{i=1}^{k} p_i \le B), where (B) is your budget.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
1. An integer (n) denoting the number of items.
2. (n) space-separated integers representing the prices of the items.
3. An integer representing the budget.
outputFormat
The output is printed to standard output (stdout) and consists of two space-separated integers: the maximum number of items that can be purchased and the total sum spent on these items.## sample
5
1 12 5 111 200
10
2 6