#C9702. Minimum Days to Complete Tasks
Minimum Days to Complete Tasks
Minimum Days to Complete Tasks
You are given a list of tasks where each task requires a certain number of hours to complete, and an integer d
representing the maximum number of hours you can work in a single day. Your goal is to determine the minimum number of days required to finish all tasks without exceeding the daily limit.
You may complete the tasks in any order. Formally, if you have n tasks with durations \(t_1, t_2, \ldots, t_n\) and a daily working limit \(d\), you need to partition the tasks into the minimum number of groups such that the sum of durations in each group does not exceed \(d\).
Input/Output: The problem involves reading from standard input and writing the result to standard output.
Note: Although this problem is related to the bin packing problem which is NP-hard in general, you can implement a greedy strategy (by sorting tasks in descending order and scheduling tasks for each day) to obtain a solution that works correctly for the provided test cases.
inputFormat
The first line contains two integers \(n\) and \(d\) where \(n\) is the number of tasks and \(d\) is the maximum number of hours that can be worked in one day. The second line contains \(n\) space-separated integers representing the durations of the tasks.
Example:
4 5 4 3 2 1
outputFormat
Output a single integer representing the minimum number of days required to complete all tasks.
Example:
2## sample
4 5
4 3 2 1
2
</p>