#C7988. Maximum Items That Can Be Packed in the Bag

    ID: 51919 Type: Default 1000ms 256MiB

Maximum Items That Can Be Packed in the Bag

Maximum Items That Can Be Packed in the Bag

You are given a bag with a weight capacity W and a set of items, each with a specific weight. Your task is to determine the maximum number of items that can be placed into the bag without exceeding its weight capacity. In each test case, you are provided the number of items N, the maximum weight capacity W, and a list of N item weights.

The optimal strategy is to pick the lighter items first. Formally, if we sort the weights in increasing order, and let \(a_1, a_2, \dots, a_N\) be the sorted weights, then you should choose the maximum integer \(k\) such that

[ a_1 + a_2 + \cdots + a_k \leq W ]

It is guaranteed that each test case follows the above format.

inputFormat

The input is given from the standard input (stdin) and has the following format:

  • The first line contains an integer T representing the number of test cases.
  • For each test case, there are two lines:
    • The first line contains two integers N and W where N is the number of items available and W is the weight capacity of the bag.
    • The second line contains N space-separated integers representing the weights of the items.

outputFormat

For each test case, print a single integer on a new line which is the maximum number of items that can fit in the bag without exceeding the weight capacity. The output is printed to the standard output (stdout).

## sample
2
4 10
2 3 5 6
3 8
5 4 3
3

2

</p>