#C10475. Maximizing Task Completion

    ID: 39684 Type: Default 1000ms 256MiB

Maximizing Task Completion

Maximizing Task Completion

You are given n tasks, each requiring a certain amount of time to complete, and a total time limit T. Your goal is to determine the maximum number of tasks that can be completed without exceeding the total time allowed.

You are allowed to perform the tasks in any order. An optimal strategy is to select the tasks that take the least time first. Mathematically, given a list of times \(t_1, t_2, \ldots, t_n\), you want to find the largest integer \(k\) such that there exists a subset of \(k\) tasks with the total time summing up to at most \(T\).

inputFormat

The input is read from stdin and consists of:

  • A line containing two integers \(n\) and \(T\), where \(n\) is the number of tasks and \(T\) is the maximum total time allowed.
  • A second line containing \(n\) integers representing the individual time required to complete each task.

outputFormat

Output a single integer to stdout representing the maximum number of tasks that can be completed within the given time limit.

## sample
6 15
2 3 5 8 12 1
4

</p>