#K85037. Subset Sum Existence

    ID: 36552 Type: Default 1000ms 256MiB

Subset Sum Existence

Subset Sum Existence

Given an array of integers and a target integer (T), determine if there exists a subset of the array whose sum is exactly (T). In other words, given an array (a_1, a_2, \dots, a_n) and an integer (T), decide if there exists a subset (S \subseteq {1,2,\dots,n}) such that (\sum_{i \in S} a_i = T). This problem requires you to output "YES" if such a subset exists, and "NO" otherwise. Input is read from standard input and output is printed to standard output. The array elements and the target may be negative as well.

inputFormat

The first line of input contains two space-separated integers (n) and (T), where (n) is the number of elements in the array and (T) is the target sum. The second line contains (n) space-separated integers representing the array elements.

outputFormat

Print "YES" if there exists a subset of the array that sums to (T); otherwise, print "NO".## sample

5 9
1 2 3 4 5
YES