#C11662. Minimum Number of Elves
Minimum Number of Elves
Minimum Number of Elves
In this problem, you are given a number of toy requests, each with an associated difficulty level. Each elf is capable of handling a sequence of toy requests as long as the total difficulty does not exceed a given maximum limit ( m ). Formally, given ( n ) toy requests with difficulty levels ( d_1, d_2, \dots, d_n ), an elf can be assigned a subset of these requests if ( \sum d_i \leq m ). Your task is to determine the minimum number of elves required to complete all toy requests.
The problem can be solved using a greedy strategy: sort the tasks in descending order and repeatedly pick the largest remaining tasks that fit within the current elf's capacity until all tasks are assigned.
inputFormat
Input is read from standard input (stdin).
The first line contains two space-separated integers: ( n ) (the number of toy requests) and ( m ) (the maximum total difficulty an elf can handle).
The second line contains ( n ) space-separated integers representing the difficulty levels of the toy requests.
outputFormat
Output a single integer to standard output (stdout), which is the minimum number of elves required to complete all the toy requests.## sample
5 10
1 2 3 4 5
2
</p>