#K53647. Taco Subset Sum
Taco Subset Sum
Taco Subset Sum
You are given a list of n integers and a target sum x. Your task is to determine whether there exists a subset of the given numbers whose sum is exactly x. Formally, given an array arr of length n and an integer x, decide if there exists a subset S \subseteq \{arr_1, arr_2, \dots, arr_n\} such that
[ \sum_{a \in S} a = x ]
Note that each number in the array may be used at most once in forming the subset.
Input: The input is read from standard input.
Output: The answer should be printed to standard output as either YES
or NO
.
inputFormat
The first line contains two integers n
and x
— the number of elements in the array and the target sum, respectively.
The second line contains n
space-separated integers representing the array arr
.
outputFormat
Print a single line containing YES
if there exists a subset of arr
whose sum is exactly x
; otherwise, print NO
.
5 10
1 2 3 4 5
YES