#K4491. Minimum Subset Elements for Target Sum
Minimum Subset Elements for Target Sum
Minimum Subset Elements for Target Sum
In this problem, you are given an array of positive integers and a target sum ( t ).
Your task is to determine the minimum number of elements from the array that add up exactly to ( t ). If it is not possible to form ( t ) using any subset of the given elements, output (-1).
Input: The input contains multiple test cases. The first line contains an integer ( T ), the number of test cases.
Output: For each test case, output a single integer representing the minimum number of elements required to sum up to ( t ), or (-1) if it is impossible.
inputFormat
The first line of input contains an integer ( T ), the number of test cases. Each test case consists of two parts:
1. A line containing two integers ( n ) and ( t ), where ( n ) is the number of elements in the array and ( t ) is the target sum.
2. A line containing ( n ) positive integers separated by spaces, representing the array elements.
outputFormat
For each test case, output a single line containing one integer: the minimum number of elements required whose sum equals ( t ). If no subset sum equals ( t ), output (-1).## sample
3
5 11
1 2 3 5 10
4 9
3 5 7 8
3 6
4 5 6
2
-1
1
</p>