#K9361. Maximizing the Number of Gifts Within Capacity

    ID: 38458 Type: Default 1000ms 256MiB

Maximizing the Number of Gifts Within Capacity

Maximizing the Number of Gifts Within Capacity

You are given a bag with a maximum capacity (C) and a list of gift weights. Your task is to determine the maximum number of gifts you can choose such that the total weight does not exceed (C). The optimal strategy is to select the lightest gifts first.

For example, given gift weights [2, 3, 5, 7] and a capacity of 10, the maximum number of gifts that can be carried is 3.

inputFormat

The input is provided via standard input (stdin) in two lines:

1. The first line contains two integers (n) and (C), where (n) is the number of gifts and (C) is the bag's capacity.

2. The second line contains (n) space-separated integers representing the weights of the gifts. If (n = 0), the second line will be empty.

outputFormat

Output a single integer to standard output (stdout) representing the maximum number of gifts that can be carried without exceeding the capacity.## sample

4 10
2 3 5 7
3