#K36557. Maximizing the Number of Tasks
Maximizing the Number of Tasks
Maximizing the Number of Tasks
You are given a total time limit \(T\) and a list of tasks, where each task takes a certain amount of time to complete. Your goal is to determine the maximum number of tasks that can be completed without the sum of their durations exceeding \(T\). To achieve the maximum count, the tasks may be completed in any order. It is optimal to first complete the tasks with the minimum durations.
Input Format: The input consists of multiple lines. The first line contains the integer \(T\), representing the total allowed time. The second line contains an integer \(n\), denoting the number of tasks. The third line contains \(n\) space-separated positive integers, each representing the duration of a task.
Output Format: A single integer representing the maximum number of tasks that can be completed without exceeding \(T\).
Note: You should read input from standard input (stdin) and write your output to standard output (stdout).
inputFormat
The input is given via standard input (stdin) and has the following format:
Line 1: An integer (T) representing the maximum total time allowed. Line 2: An integer (n) representing the number of tasks. Line 3: (n) space-separated integers, where each integer represents the duration of a task.
outputFormat
The output should be printed to standard output (stdout) and contain a single integer: the maximum number of tasks that can be completed without exceeding the total time (T).## sample
10
5
2 3 1 5 4
4