#K58197. Maximum Ingredients

    ID: 30589 Type: Default 1000ms 256MiB

Maximum Ingredients

Maximum Ingredients

Anna wants to purchase as many different ingredients as possible while staying within her budget. The store offers a special deal: when buying any group of \(m\) ingredients together, the cheapest one in that group is free. In other words, if you choose \(m\) ingredients with prices \(p_1, p_2, \dots, p_m\), you only pay \(\sum_{i=1}^{m} p_i - \min\{p_1, p_2, \dots, p_m\}\). You may combine group purchases and individual purchases in any order in order to maximize the total number of ingredients you can buy without exceeding your budget.

Given the list of ingredient prices, determine the maximum number of ingredients Anna can purchase.

inputFormat

The first line contains an integer (T), the number of test cases. For each test case, the first line contains three integers (n), (b), and (m) where:

  • (n) is the number of available ingredients,
  • (b) is the total budget, and
  • (m) is the size of a purchase group for the special offer.

The second line of each test case contains (n) space-separated integers representing the prices of the ingredients.

outputFormat

For each test case, print a single integer on a new line denoting the maximum number of ingredients that can be bought.## sample

3
5 20 3
1 2 3 4 5
4 15 2
3 4 5 8
3 30 3
10 10 10
5

4 3

</p>