#K4366. Card Sum Combination

    ID: 27359 Type: Default 1000ms 256MiB

Card Sum Combination

Card Sum Combination

You are given n piles of cards. Each pile contains one or more integers. Your task is to determine whether it is possible to pick exactly one card from each pile such that the sum of the selected cards is equal to a given target s.

Formally, given n piles where the i-th pile contains a list of integers, determine if there exists a combination of cards (one from each pile) for which

\(\sum_{i=1}^{n} a_i = s\)

where \(a_i\) is the card chosen from the i-th pile. If such a combination exists, print "YES"; otherwise, print "NO".

inputFormat

The input is read from standard input (stdin) and has the following format:

n s
k1 a11 a12 ... a1k1
k2 a21 a22 ... a2k2
...
kn an1 an2 ... ankn

Where:

  • n is the number of piles.
  • s is the target sum.
  • Each of the next n lines begins with an integer ki (the number of cards in the i-th pile), followed by ki integers representing the values of the cards in that pile.

outputFormat

The output is a single line, printed to standard output (stdout), containing either "YES" if there exists a valid combination of cards such that their sum equals s, or "NO" if no such combination exists.

## sample
3 15
3 8 5 2
4 12 7 4 3
2 6 1
YES