#C11157. Exact Points Collection
Exact Points Collection
Exact Points Collection
You are given a set of levels, each with a certain number of points. Your task is to determine whether it is possible to choose a subset of these levels such that the total sum of points is exactly equal to a given target value y.
The input begins with two integers: n (the number of levels) and y (the target points). The next line contains n integers representing the points of each level.
Your output should be a single line containing "YES" if there exists a combination of levels whose sum is exactly y, and "NO" otherwise.
This can be formulated as a subset sum problem. In mathematical notation, given a list \(a_1, a_2, \dots, a_n\) and a target \(y\), determine if there exists a subset \(S \subseteq \{1,2,...,n\}\) such that \(\sum_{i\in S} a_i = y\).
inputFormat
The first line contains two integers n
and y
separated by a space.
The second line contains n
space separated integers, which are the points for each level.
You should read the input from stdin.
outputFormat
Output a single line to stdout containing either "YES" if a subset of levels sums to y
, or "NO" otherwise.
3 15
3 7 5
YES