#C6191. Minimum Urns to Buy Candies

    ID: 49924 Type: Default 1000ms 256MiB

Minimum Urns to Buy Candies

Minimum Urns to Buy Candies

You are given (n) urns, each containing a certain number of candies, and an integer (m) representing the required number of candies. Your task is to determine the minimum number of urns that must be emptied completely to collect at least (m) candies. Formally, if the candies in the urns when sorted in non-increasing order are (c_1, c_2, \dots, c_n), find the smallest (k) such that [ \sum_{i=1}^{k} c_i \ge m ]

This problem can be solved using a greedy approach by taking the urns with the largest number of candies first.

inputFormat

The input is read from standard input (stdin). The first line contains two integers (n) and (m), where (n) is the number of urns and (m) is the required number of candies. The second line contains (n) integers (c_1, c_2, \dots, c_n) representing the number of candies in each urn.

outputFormat

Output a single integer to standard output (stdout) representing the minimum number of urns that must be emptied to obtain at least (m) candies.## sample

4 10
3 5 2 8
2