#K71692. Maximum Task Completion
Maximum Task Completion
Maximum Task Completion
You are given a list of tasks, where each task requires a certain amount of resource, and an overall available resource R. Your goal is to determine the maximum number of tasks that can be completed without exceeding the resource R. You are allowed to complete the tasks in any order.
A key insight is that performing tasks with lower resource requirements first allows you to complete more tasks. Mathematically, if the sorted tasks are represented as \(a_1, a_2, \dots, a_n\), then you need to find the largest \(k\) such that:
\(\sum_{i=1}^{k} a_i \leq R\)
Input is provided via stdin and the result should be printed to stdout.
inputFormat
The input consists of two lines:
- The first line contains two integers n and R, where n is the number of tasks and R is the total available resource.
- The second line contains n integers, each representing the resource requirement of each task. If n is 0, the second line may be omitted.
outputFormat
Output a single integer: the maximum number of tasks that can be completed without exceeding the resource R.
## sample4 300
100 200 150 80
2