CF1710A.Color the Picture
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A picture can be represented as an n×m grid ( n rows and m columns) so that each of the n⋅m cells is colored with one color. You have k pigments of different colors. You have a limited amount of each pigment, more precisely you can color at most ai cells with the i -th pigment.
A picture is considered beautiful if each cell has at least 3 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 1≤x1,x2≤n and 1≤y1,y2≤m , the cell in the x1 -th row and y1 -th column is a toroidal neighbor of the cell in the x2 -th row and y2 -th column if one of following two conditions holds:
- x1−x2≡±1(modn) and y1=y2 , or
- y1−y2≡±1(modm) and x1=x2 .
Notice that each cell has exactly 4 toroidal neighbors. For example, if n=3 and m=4 , the toroidal neighbors of the cell (1,2) (the cell on the first row and second column) are: (3,2) , (2,2) , (1,3) , (1,1) . They are shown in gray on the image below:
The gray cells show toroidal neighbors of (1,2) .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 t ( 1≤t≤104 ). The description of the test cases follows.
The first line of each test case contains three integers n , m , and k ( 3≤n,m≤109 , 1≤k≤105 ) — the number of rows and columns of the picture and the number of pigments.
The next line contains k integers a1,a2,…,ak ( 1≤ai≤109 ) — ai is the maximum number of cells that can be colored with the i -th pigment.
It is guaranteed that the sum of k over all test cases does not exceed 105 .
输出格式
For each test case, print "Yes" (without quotes) if it is possible to color a beautiful picture. Otherwise, print "No" (without quotes).
输入输出样例
输入#1
6 4 6 3 12 9 8 3 3 2 8 8 3 3 2 9 5 4 5 2 10 11 5 4 2 9 11 10 10 3 11 45 14
输出#1
Yes No Yes Yes No No
说明/提示
In the first test case, one possible solution is as follows:
In the third test case, we can color all cells with pigment 1 .