#C7975. Subsequence Sum Problem
Subsequence Sum Problem
Subsequence Sum Problem
Given an integer N and an integer X, along with a list of N positive integers A, determine whether there exists a non-empty subsequence of A whose sum of elements is exactly equal to 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.
Your task is to decide if there exists such a subsequence. Formally, you need to determine if there exists a non-empty subset \(S \subseteq \{1,2,\dots,N\}\) such that \(\sum_{i \in S} A_i = X\). If it exists, print YES
, otherwise print NO
.
inputFormat
The first line of input contains two space-separated integers, N and X. The second line contains N space-separated integers representing the array A.
outputFormat
Print a single line containing YES
if there exists a non-empty subsequence of A that sums up to X; otherwise, print NO
.## sample
3 5
1 2 3
YES