#K57682. Subset Sum Finder
Subset Sum Finder
Subset Sum Finder
Given an array of positive integers (a_1, a_2, \ldots, a_n) and a target integer (T), determine whether there exists a non-empty subsequence whose sum exactly equals (T). A non-empty subsequence is any subset of the array elements (the elements do not need to be contiguous). Output YES
if such a subsequence exists and NO
otherwise.
Note: A subsequence must contain at least one element.
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 positive integers representing the array elements.
outputFormat
Print YES
if there exists a non-empty subsequence whose sum is exactly (T); otherwise, print NO
.## sample
5 9
1 2 3 4 5
YES