GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 29 July 2022

[Solution] Color the Picture Codeforces Solution



C. Color the Picture
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A picture can be represented as an n×m grid (n rows and m columns) so that each of the nm 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 1x1,x2n and 1y1,y2m, 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:

  • x1x2±1(modn) and y1=y2, or
  • y1y2±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

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

 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?

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t104). The description of the test cases follows.







The first line of each test case contains three integers nm, and k (3n,m1091k105) — the number of rows and columns of the picture and the number of pigments.

The next line contains k integers a1,a2,,ak (1ai109) — 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.

Output

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