#C6210. Maximum Books
Maximum Books
Maximum Books
Masha has a collection of n books, each requiring a certain number of hours to read. She also has h flexible hours available to read. Masha wants to maximize the number of books she can completely read by choosing the books that require the least amount of time. More specifically, she can choose a subset of the books such that the sum of their required reading hours does not exceed h. Formally, if the chosen subset consists of books with reading times \(a_1, a_2, \dots, a_k\), they must satisfy:
[ a_1 + a_2 + \cdots + a_k \leq h ]
Your task is to determine the maximum number of books Masha can read. The optimal strategy is to sort the list of required hours in ascending order and keep selecting books until the total reading time would exceed \(h\).
inputFormat
The first line contains two integers n (the number of books) and h (the total available hours). The second line contains n space-separated integers, where each integer represents the number of hours required to read a book.
Constraints: \(1 \leq n \leq 10^5\); \(0 \leq h \leq 10^9\); Each book's reading time is a positive integer.
outputFormat
Output a single integer: the maximum number of books Masha can completely read within the available hours.
## sample5 10
1 2 3 4 5
4