#C7569. Maximum Problems Solved

    ID: 51454 Type: Default 1000ms 256MiB

Maximum Problems Solved

Maximum Problems Solved

You are given n problems and a total available time T. Each problem requires a certain amount of time to solve, given by the array times. Your task is to determine the maximum number of problems that can be solved without exceeding the total time T.

The challenge can be summarized by the following steps:

  1. Sort the list of problem times in ascending order.
  2. Select problems sequentially until adding the next problem would exceed the total available time T.

Mathematically, if the sorted times are \(t_1, t_2, \ldots, t_n\), find the largest integer \(k\) such that:

[ \sum_{i=1}^{k} t_i \leq T ]

Constraints:

  • \(1 \leq n \leq 10^5\)
  • \(1 \leq T \leq 10^9\)
  • \(1 \leq t_i \leq 10^6\)

inputFormat

The input is read from stdin and consists of:

  • A line with two integers \(n\) and \(T\), where \(n\) is the number of problems and \(T\) is the total available time.
  • A second line with \(n\) space-separated integers representing the time required for each problem.

outputFormat

Output a single integer on stdout representing the maximum number of problems that can be solved within the time limit \(T\).

## sample
5 15
5 3 8 6 2
3