#K12466. Optimal Container Selection

    ID: 23697 Type: Default 1000ms 256MiB

Optimal Container Selection

Optimal Container Selection

You are given N containers each with a specified capacity. Your task is to determine the minimum number of containers required such that the total capacity is at least M liters. In other words, if the containers have capacities \(c_1, c_2, \ldots, c_N\), you need to find the smallest \(k\) such that:

\(\sum_{i=1}^{k} c_i \ge M\)

The containers can be used in any order. A common strategy is to sort the containers in descending order and then keep adding the largest available containers until the sum is at least \(M\). This problem tests your ability to apply sorting and greedy algorithms.

inputFormat

The first line contains two integers separated by a space: N (the number of containers) and M (the minimum total capacity required).

The second line contains N space-separated integers, each representing the capacity of a container.

outputFormat

Output a single integer representing the minimum number of containers needed such that their total capacity is at least M.

If it is not possible to reach M with the given containers, output the total number of containers available.

## sample
5 13
5 8 3 7 9
2