#K49457. Minimum Donations Problem

    ID: 28646 Type: Default 1000ms 256MiB

Minimum Donations Problem

Minimum Donations Problem

You are given a series of test cases. In each test case, you are provided with a target donation amount and a list of donation values. Your task is to determine the minimum number of donations needed such that the sum is exactly equal to the target. If it is not possible to reach the target using any combination (with repetitions allowed) of the given donation values, output -1.

This problem can be modeled as a variant of the coin change problem. In particular, given a target value \(T\) and donation values \(d_1, d_2, \dots, d_n\), you have to find the minimum number of coins (donations) required such that their sum equals \(T\). If no combination exists, output \(-1\).

inputFormat

The first line of input contains an integer \(t\) representing the number of test cases. For each test case, the first line contains two integers \(n\) and \(T\) where \(n\) is the number of available donation values and \(T\) is the target donation amount. The second line of each test case contains \(n\) space-separated integers representing the donation values.

For example:

2
3 11
1 2 5
4 8
3 4 5 6

outputFormat

For each test case, output a single line containing the minimum number of donations required to exactly reach the target \(T\). If it is not possible, output -1.

For the input sample above, the expected output is:

3
2
## sample
2
3 11
1 2 5
4 8
3 4 5 6
3

2

</p>