#C9216. Maximum Tasks Completion
Maximum Tasks Completion
Maximum Tasks Completion
Brian has a set of tasks, each requiring a given amount of time to complete. Given the total available time T and the list of individual task durations, determine the maximum number of tasks Brian can complete.
You are allowed to perform the tasks in any order. The optimal strategy is to perform tasks in increasing order of their durations, ensuring that the sum of task times does not exceed T.
The problem can be mathematically formulated as:
$$\max \{ k \;|\; \sum_{i=1}^{k} t_i \le T \}$$
where \(t_i\) denotes the task durations sorted in non-decreasing order.
inputFormat
The input consists of two lines. The first line contains two integers T and N, where T is the available time and N is the number of tasks. The second line contains N space-separated integers representing the time required for each task.
outputFormat
Output a single integer, which is the maximum number of tasks that can be completed within the available time T.## sample
10 4
2 3 1 2
4