#C8700. Subset Sum Problem
Subset Sum Problem
Subset Sum Problem
Given an integer N representing the number of elements, a target integer K, and a list of N integers, determine if there exists a subset of these integers whose sum is exactly K. The solution should output YES if such a subset exists and NO otherwise.
This can be mathematically stated as finding a subset \( S \subseteq \{1,2,...,N\} \) such that \( \sum_{i \in S} a_i = K \), where \( a_i \) are the given numbers.
inputFormat
The input is given in two lines.
The first line contains two integers N and K separated by a space, where 1 ≤ N ≤ 20 and ( -10^9 \le K \le 10^9 ).
The second line contains N space-separated integers representing the list of numbers.
outputFormat
Output a single line with either YES if there exists a subset of the given numbers whose sum is exactly K, or NO if no such subset exists.## sample
4 0
-7 -3 2 5
YES
</p>