#C4542. Subset Sum Existence

    ID: 48092 Type: Default 1000ms 256MiB

Subset Sum Existence

Subset Sum Existence

You are given a list of n integers and a target sum S. Your task is to determine whether there exists a subset of the given integers whose sum is exactly equal to S. In mathematical terms, find a subset I such that \(\sum_{i\in I} a_i = S\).

Output YES if such a subset exists; otherwise, output NO.

inputFormat

The input is given through stdin and consists of two lines:

  • The first line contains two integers n and S separated by a space, where n is the number of integers and S is the target sum.
  • The second line contains n space-separated integers representing the array values.

outputFormat

Output a single line to stdout which contains either YES if there exists a subset that sums to S, or NO otherwise.

## sample
6 9
3 34 4 12 5 2
YES