SDE Path

Subset Sum Equal to Target

Medium

Subset Sum Equal to Target

Determine whether a subset of an array sums to a given target.

Input format

The first line contains N and TARGET. The second line contains N integers (1–30).

Output format

Print true if a subset sums to TARGET, false otherwise.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
1 81
5
Expected output
false
Example 2
Input
8 39
29 15 30 24 11 5 22 16
Expected output
true