#C5862. Subsequence Sum Problem
Subsequence Sum Problem
Subsequence Sum Problem
You are given an array of n integers and a target integer k. Your task is to determine whether there exists a subsequence of the array whose sum equals k.
A subsequence is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. Formally, given an array \(a_1, a_2, \ldots, a_n\), you need to check if there exists a set of indices \(1 \le i_1 < i_2 < \ldots < i_m \le n\) such that:
\(a_{i_1} + a_{i_2} + \cdots + a_{i_m} = k\)
Note that the empty subsequence is considered to have a sum of \(0\). Your solution should read from stdin
and write the result to stdout
as either "Yes" (if such a subsequence exists) or "No" (otherwise).
inputFormat
The first line contains two integers n and k separated by a space, where n is the number of elements in the array and k is the target sum. The second line contains n space-separated integers representing the array elements.
outputFormat
Output a single line containing "Yes" if there exists a subsequence of the array that sums up to k, otherwise output "No".
## sample5 9
2 3 1 2 8
Yes