#K10726. Subset Sum Problem

    ID: 23311 Type: Default 1000ms 256MiB

Subset Sum Problem

Subset Sum Problem

You are given a set of n integers and a target value t. Your task is to determine whether there exists a subset of the given integers whose sum is exactly equal to t.

Formally, let \(S = \{a_1, a_2, \dots, a_n\}\). Determine if there exists a subset \(S' \subseteq S\) such that \(\sum_{a \in S'} a = t\). Note that the empty subset has a sum of 0. This is a classic example of the Subset Sum Problem which can be efficiently solved using dynamic programming for moderate values of t.

inputFormat

The first line of input contains two space-separated integers n and t where n is the number of integers and t is the target sum. The second line contains n space-separated integers.

Constraints:

  • 1 \(\leq\) n \(\leq\) 103
  • 0 \(\leq\) t \(\leq\) 105
  • Integers can be positive or zero.

outputFormat

Output a single line containing either YES if a subset exists whose sum is exactly t, or NO otherwise.

## sample
4 10
1 2 3 4
YES

</p>