[Solution] Color the Picture Codeforces Solution
A picture can be represented as an grid ( rows and columns) so that each of the cells is colored with one color. You have pigments of different colors. You have a limited amount of each pigment, more precisely you can color at most cells with the -th pigment.
A picture is considered beautiful if each cell has at least toroidal neighbors with the same color as itself.
Two cells are considered toroidal neighbors if they toroidally share an edge. In other words, for some integers and , the cell in the -th row and -th column is a toroidal neighbor of the cell in the -th row and -th column if one of following two conditions holds:
- and , or
- and .
Notice that each cell has exactly toroidal neighbors. For example, if and , the toroidal neighbors of the cell (the cell on the first row and second column) are: , , , . They are shown in gray
on the image below:
Is it possible to color all cells with the pigments provided and create a beautiful picture?
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains three integers , , and (, ) — the number of rows and columns of the picture and the number of pigments.
The next line contains integers () — is the maximum number of cells that can be colored with the -th pigment.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print "Yes" (without quotes) if it is possible to color a beautiful picture. Otherwise, print "No" (without quotes).
No comments:
Post a Comment