#C10161. Maximum Flower Planting
Maximum Flower Planting
Maximum Flower Planting
Mary has a collection of different types of flowers, each requiring a certain number of hours of sunlight to thrive. She wants to plant as many different types as possible without exceeding the total available daily sunlight hours, \(H\). Given \(N\) types of flowers and an array \(S\) representing the hours of sunlight each type requires, your task is to determine the maximum number of types Mary can plant such that the total required sunlight does not exceed \(H\).
Note: You are given multiple test cases. For each test case, the first line contains two integers: \(N\) (the number of flower types) and \(H\) (the total available hours of sunlight). The next line contains \(N\) integers representing the sunlight requirements of each flower type. You should output the maximum number of flower types that Mary can plant for each test case on a new line.
To solve this problem, one effective strategy is to sort the array of required hours \(S\) in non-decreasing order, and then select the flowers one by one while keeping a cumulative sum. As soon as adding a new flower violates the sunlight constraint \(H\), you should stop.
inputFormat
The input is read from stdin and has the following format:
T N H S[0] S[1] ... S[N-1] ... (repeated for T test cases)
Where:
T
is the number of test cases.- For each test case, the first line contains two integers \(N\) and \(H\): the number of flower types and the total available hours of sunlight.
- The next line contains \(N\) space-separated integers representing the sunlight requirements for each flower type.
outputFormat
For each test case, print on a separate line the maximum number of different flower types that can be planted without the total sunlight requirement exceeding \(H\). The output is written to stdout.
## sample1
5 10
2 3 4 5 1
4
</p>