A good subset

5

3 votes
Binary Search, 2D dynamic programming, Dynamic Programming, Algorithms
Problem

You are given an array A that consists of N positive integers. A subset of the array A is good when the sum of the elements of the subset is K or greater.

An element of the array is unnecessary if for any good subset of the array containing i element, the set that can be obtained by eliminating i from the subset is also good.

Find the number of the unnecessary elements present in array A

Input format

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains two space-separated integers N and K.
  • The second line of each test case contains N space-separated integers denoting array A.

Output format

For each test case, print the total number of unneccessary elements present in the array in a new line.

Constraints

1T101N50001K50001Ai5000

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For the first testcase, there are two good sets: {2,3} and {1,2,3}.

Element 1 is only contained in {1,2,3}, and this set without element 1, {2,3}, is also good. Thus, element 1 is unnecessary.

For element 2, a good set {2,3} without element 2, {3}, is not good. Thus, element 2 is NOT unnecessary.

Neither is element 3 for a similar reason, hence the answer is 1.

For the second testcase, there is no good set. Therefore, all the elements are unnecessary.

Editor Image

?