#C3975. Subset Sum Existence
Subset Sum Existence
Subset Sum Existence
Given a set of n integers and a target sum S, determine whether there exists a non-empty subset of these integers that sums exactly to S. In other words, find if there exists a subset \(T\) of \(\{a_1, a_2, \dots, a_n\}\) such that
Note that the integers may include negative values. Your program should read the input from standard input and output the result to standard output.
inputFormat
The first line contains two integers n and S separated by a space, where n is the number of integers and S is the target sum. The second line contains n space-separated integers.
outputFormat
Output a single line containing YES
if there exists a non-empty subset whose sum is S, otherwise output NO
.
5 9
1 2 3 4 5
YES