#C6405. Subset Sum Puzzle
Subset Sum Puzzle
Subset Sum Puzzle
Problem Description:
You are given a list of ( n ) integers representing completion times in a puzzle game and a target time ( T ). Your task is to determine if there exists a non-empty subset of these completion times whose sum is exactly ( T ). In other words, given a sequence ( a_1, a_2, \ldots, a_n ) and a target ( T ), decide whether there exists a subset ( S \subseteq {1,2,\ldots,n} ), ( S \neq \emptyset ), such that
[
\sum_{i \in S} a_i = T
]
The input consists of multiple test cases. For each test case, if such a subset exists, print YES
; otherwise, print NO
.
inputFormat
Input Format:
The first line contains an integer ( t ) denoting the number of test cases. Each test case consists of two lines:
1. The first line contains two integers ( n ) (the number of levels) and ( T ) (the target sum).
2. The second line contains ( n ) integers representing the completion times for the levels.
outputFormat
Output Format:
For each test case, output a single line containing YES
if there exists at least one non-empty subset whose sum equals ( T ); otherwise, output NO
.## sample
3
4 10
1 2 3 4
3 5
2 2 3
4 11
1 2 3 4
YES
YES
NO
</p>