#K39122. Max Books

    ID: 26351 Type: Default 1000ms 256MiB

Max Books

Max Books

You are given N books, each with a reading time denoted by Ti and a total available time M. Your task is to determine the maximum number of books that can be completely read within the time limit.

To achieve this, it is optimal to select the books with the shortest reading times first. In other words, if you sort the books by their reading times, you can keep adding them until the sum exceeds M. This can be mathematically expressed as:

$$\sum_{i=1}^{k} T_i \le M$$

Implement an efficient solution to compute the maximum number of books that can be read without exceeding the allotted time.

inputFormat

The input is given via standard input (stdin). The first line contains two integers N and M separated by a space, where N is the number of books and M is the total available time. The second line contains N space-separated integers representing the reading times of the books.

outputFormat

Output a single integer to standard output (stdout): the maximum number of books that can be read without exceeding the total time M.## sample

5 10
3 1 4 1 2
4