#K37382. Maximum Completed Tasks
Maximum Completed Tasks
Maximum Completed Tasks
You are given a list of tasks with their durations in minutes and a total available time in hours. Your task is to determine the maximum number of tasks that can be completed sequentially without exceeding the available time.
Note that tasks can be performed in any order. In order to maximize the number of tasks, a greedy strategy of selecting the tasks with the shortest durations first is optimal.
The problem can be formulated as follows:
Let \(T = [t_1, t_2, \dots, t_n]\) be a list of task durations in minutes, and let \(H\) be the available time in hours. Convert the available time to minutes, i.e., \(M = 60 \times H\). Find the maximum number of tasks that can be sequentially completed such that their total duration does not exceed \(M\).
inputFormat
The input is read from standard input. It contains two lines:
- The first line contains two integers \(n\) and \(H\) separated by a space, where \(n\) is the number of tasks (\(0 \leq n \leq 10^5\)) and \(H\) is the available time in hours.
- If \(n > 0\), the second line contains \(n\) integers representing the durations of the tasks in minutes.
outputFormat
Output a single integer to standard output representing the maximum number of tasks that can be completed sequentially.
## sample6 2
30 60 10 55 20 40
4
</p>