#K85597. Maximum Number of Tasks
Maximum Number of Tasks
Maximum Number of Tasks
You are given a list of positive integers representing the time each task requires and an integer \(K\) indicating the total available time. Your objective is to determine the maximum number of tasks that can be completed without exceeding \(K\).
A greedy approach works here. First, sort the tasks by their required time in increasing order. Then, select tasks one by one until adding the next task would exceed the available time \(K\). This strategy maximizes the number of tasks completed.
inputFormat
The first line contains two integers \(n\) and \(K\), where \(n\) is the number of tasks and \(K\) is the total available time.
The second line contains \(n\) space-separated positive integers, which denote the required time for each task.
outputFormat
Output a single integer representing the maximum number of tasks that can be completed within the given time \(K\).
## sample5 10
5 3 8 4 2
3
</p>