#C3750. Subset Sum Problem
Subset Sum Problem
Subset Sum Problem
Given an array of positive integers and a target sum \(X\), determine if there exists a subset of the array whose elements sum exactly to \(X\). You can solve this problem using dynamic programming. Consider the recurrence:
\(dp[i][j] = dp[i-1][j] \quad \text{or} \quad dp[i-1][j-a_i]\) for \(a_i \leq j\),
where \(dp[i][j]\) is true if a subset of the first \(i\) elements can sum to \(j\), and false otherwise.
inputFormat
The input is read from stdin. The first line contains two integers \(n\) and \(X\), where \(n\) denotes the number of elements in the array, and \(X\) is the target sum. The second line contains \(n\) positive integers separated by spaces, representing the array.
outputFormat
Output a single line to stdout: "YES" if there exists at least one subset whose sum equals \(X\); otherwise, output "NO".
## sample5 11
2 3 7 8 10
YES