Hide

Problem E
Tidy Racks

/problems/liuchallenge23.tidyracks/file/statement/en/img-0001.jpg

Strong as you are, you’re only able to gym very late at night so that there are enough non-occupied weights available. But after a whole day of activity at the gym, the weights are left in an unorderly mess and you feel that you have to organize the weights before you begin your exercise.

There are $N$ racks in the gym. Each rack holds a single stack of weights and each stack can hold at most $K$ weights. There exists four types of weights: 5s, 10s, 15s and 20s. You are allowed to perform the following operation (possibly zero, or more) times:

  • 1. Pick the topmost weight from any stack

  • 2. Place the weigth back on any non-full stack

You wonder if it is possible to order the weights so that each stack holds only a single type of weight by only performing the operation. Output "Yes" if it is possible, else "No".

Input

The first line of input consists of two integers $N$ ($1 \leq N \leq 10000$), the number of racks and $K$ ($1 \leq K \leq 100$), the size of each rack stack. Then follows $N$ lines. The $i$:th line ($1 \leq i \leq N$), are in the format ’$B_ i, W_1, W_2, ..., W_{B_ i}$’ with ($0 \leq B_ i \leq K$) and $W \in \{ 5,10,15,20\} $, and describes the configuration of the $i$:th stack where $W_1$ denotes the weight at the bottom of the stack.

Ouput

Output (case sensitive) a single line containing "Yes" if it is possible to order the weights using only the operation, else "No".

Sample Input 1 Sample Output 1
3 4
4 5 5 5 5
4 10 10 15 10
1 15
Yes
Sample Input 2 Sample Output 2
1 3
3 5 20 5
No

Please log in to submit a solution to this problem

Log in