#K56167. Subset Sum for Potion Frequencies

    ID: 30139 Type: Default 1000ms 256MiB

Subset Sum for Potion Frequencies

Subset Sum for Potion Frequencies

You are given a collection of potion frequencies and a target value \(v\). Your task is to determine whether there exists a non-empty subset of these frequencies whose sum equals exactly \(v\). In other words, given an array of integers \(a_1, a_2, \dots, a_n\) and an integer \(v\), decide if there exists a subset \(S \subseteq \{1,2,\dots,n\}\) such that

[ \sum_{i \in S} a_i = v ]

If such a subset exists, output YES, otherwise output NO.

Note: The subset can be empty only if \(v = 0\), which is considered valid.

inputFormat

The first line of input contains an integer \(T\) denoting the number of test cases.

For each test case, the first line contains two integers \(n\) and \(v\) where \(n\) is the number of potion frequencies and \(v\) is the target sum.

The second line contains \(n\) space-separated integers representing the potion frequencies.

outputFormat

For each test case, output a single line containing either YES if there exists a subset that sums to \(v\), or NO otherwise.

## sample
4
4 9
1 2 3 4
5 0
1 2 3 4 5
3 11
5 5 5
3 10
6 1 9
YES

YES NO YES

</p>