#C5328. Minimum Sections to Collect Items
Minimum Sections to Collect Items
Minimum Sections to Collect Items
You are given a series of sections, each containing a certain number of items. Your task is to determine the minimum number of sections required to collect at least \(M\) items. In each step, you can choose one of the remaining sections. A greedy approach works best: always pick the section with the largest number of items.
Input: The first line contains two integers \(N\) and \(M\) representing the number of sections and the minimum total number of items required, respectively. The second line contains \(N\) integers where each integer represents the number of items available in that section.
Output: Output a single integer - the minimum number of sections that must be chosen such that the total number of items is at least \(M\). It is guaranteed that the sum of items in all sections is at least \(M\).
inputFormat
The input from standard input is given in the following format:
N M a1 a2 a3 ... aN
Where:
- N is the number of sections.
- M is the minimum number of items required.
- a1, a2, ..., aN are the numbers of items in each section.
outputFormat
The output should be a single integer representing the minimum number of sections required to collect at least \(M\) items. The answer is printed to standard output.
## sample4 10
3 8 2 1
2