#K93422. Maximizing Completed Tasks
Maximizing Completed Tasks
Maximizing Completed Tasks
You are given n tasks with individual durations and a total available duration T. Your goal is to complete as many tasks as possible without exceeding the total duration T. The optimal strategy is to perform the tasks that take the least time first.
This problem can be formally defined as follows: Given an integer n and a total available time T, and a list of n positive integers representing the duration of each task, determine the maximum number of tasks that can be completed such that the sum of their durations does not exceed T.
Hint: Sorting the list of durations in ascending order before accumulating them can lead to an optimal solution.
inputFormat
Input is read from standard input (stdin). The first line contains two integers n and T, where n is the number of tasks and T is the total available duration. The second line contains n space-separated integers representing the individual durations of the tasks.
outputFormat
Output a single integer on standard output (stdout) denoting the maximum number of tasks that can be completed within the total available duration T.## sample
5 10
1 2 3 4 5
4