#C7542. Subsequence Sum Checker
Subsequence Sum Checker
Subsequence Sum Checker
You are given an integer sequence and three integers \(n\), \(m\) and \(S\). Your task is to determine if there exists a subsequence of exactly \(m\) elements from the sequence whose sum is exactly \(S\). A subsequence is a sequence that can be derived from the original sequence by deleting some elements without changing the order of the remaining elements.
For example, if you are given a sequence [1, 2, 3, 4, 5] with \(n = 5\), \(m = 3\) and \(S = 6\), then one possible subsequence is [1, 2, 3] which sums to 6. On the other hand, if the sequence is [5, 5, 5, 5] with \(n = 4\), \(m = 2\) and \(S = 12\), no subsequence of 2 elements can sum to 12.
The input consists of multiple test cases. For each test case, you will be given the parameters \(n\), \(m\), \(S\) followed by a line of \(n\) integers. Input terminates with a line where \(n = m = S = 0\).
inputFormat
The input is read from standard input (stdin) and consists of multiple test cases. Each test case is described as follows:
- A line containing three integers \(n\), \(m\) and \(S\), where \(n\) is the number of elements in the sequence, \(m\) is the length of the subsequence to check, and \(S\) is the target sum.
- A line containing \(n\) integers, representing the sequence.
The input terminates when a line with "0 0 0" is encountered. This test case should not be processed.
outputFormat
For each test case, output a single line to standard output (stdout) containing either "Yes" if there exists a subsequence of length \(m\) whose sum is \(S\), or "No" otherwise.
## sample5 3 6
1 2 3 4 5
4 2 12
5 5 5 5
0 0 0
Yes
No
</p>