#K40162. Subsequence Sum Existence
Subsequence Sum Existence
Subsequence Sum Existence
Given an integer array \(A\) of length \(n\) and an integer \(X\), determine whether there exists a non-empty subsequence of \(A\) whose sum is exactly \(X\). A subsequence is defined as a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.
The problem can be formalized as finding a non-empty set \(S \subseteq \{1,2,\ldots,n\}\) such that:
$$\sum_{i\in S} A_i = X$$
inputFormat
The input is given via standard input. The first line contains an integer (n), the number of elements in the array. The second line contains (n) space-separated integers representing the array (A). The third line contains an integer (X), the target sum.
outputFormat
Output a single line to standard output: "YES" if there exists a non-empty subsequence whose sum equals (X); otherwise, output "NO".## sample
5
1 2 3 4 5
9
YES