#C798. Maximum Items Purchase

    ID: 51910 Type: Default 1000ms 256MiB

Maximum Items Purchase

Maximum Items Purchase

Sudha wants to maximize the number of items she can purchase given a limited budget. You are given a list of prices for various items and a total budget. The challenge is to determine the maximum number of items that can be bought without exceeding the budget.

Approach: Sort the list of prices in increasing order and then continuously add the prices until the current total would exceed the budget. The count of items that have been added is the answer.

Note: Use efficient sorting and iteration since the input size can be large.

inputFormat

The first line of input contains an integer n, the number of items. The second line contains n space-separated integers representing the prices of the items. The third line contains an integer representing the total budget.

outputFormat

Output a single integer, which is the maximum number of items that can be purchased without exceeding the budget.## sample

5
20 10 40 50 30
70
3

</p>