#K56432. Taco's Subsequence Sum Problem

    ID: 30197 Type: Default 1000ms 256MiB

Taco's Subsequence Sum Problem

Taco's Subsequence Sum Problem

Given an array of n integers and a target integer k, determine whether there exists a subsequence (possibly empty) of the array whose sum is exactly k. In other words, check if it is possible to choose a subset of the numbers (order does not matter) such that their total sum is equal to k. Note that by definition, the empty subsequence has a sum of 0.

This problem can be solved using dynamic programming. The typical recurrence is given by:

[ \text{dp}[j] = \text{dp}[j] \lor \text{dp}[j - \text{num}], \quad \text{for each } num \text{ in the array and } j \text{ from } k \text{ down to } num. ]

For each test case, output "YES" if such a subsequence exists, or "NO" otherwise.

inputFormat

The first line of input contains a single integer T representing the number of test cases. Each test case starts with a line containing two integers n and k, where n is the size of the array and k is the target sum. The following line contains n space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line containing either "YES" if there exists a subsequence whose sum is exactly k, or "NO" otherwise.

## sample
2
5 9
1 2 3 4 5
4 8
1 3 9 2
YES

NO

</p>