#K48437. Maximize Item Purchases

    ID: 28420 Type: Default 1000ms 256MiB

Maximize Item Purchases

Maximize Item Purchases

Maria loves shopping and wants to maximize the number of items she can buy given her limited budget. You are provided with an integer ( n ) representing the number of available items, a list of prices for these items, and an integer ( budget ). Your task is to determine the maximum number of items that can be purchased without exceeding the budget. The items can be bought in any order, but you must choose the cheapest items first to maximize the count.

For example, if ( n = 5 ), prices are given by the space-separated string "1 12 5 111 200" and ( budget = 10 ), then the maximum number of purchasable items is 2 because Maria can only afford items priced at 1 and 5.

inputFormat

The input consists of three lines:

  1. The first line contains an integer ( n ), the number of available items.
  2. The second line contains ( n ) space-separated integers, representing the prices of the items.
  3. The third line contains an integer ( budget ), the total budget available to Maria.

outputFormat

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

5
1 12 5 111 200
10
2

</p>