#C5741. Validate Shelf Arrangement

    ID: 49424 Type: Default 1000ms 256MiB

Validate Shelf Arrangement

Validate Shelf Arrangement

You are given a series of test cases where each test case represents an arrangement of products on shelves. Each shelf has a maximum weight capacity and products placed on the shelf have a certain weight. Your task is to verify if the arrangement is valid, i.e. for every shelf cell the product's weight does not exceed the shelf's capacity.

In each test case, the following input is provided:

  • Two integers \(m\) and \(n\) representing the dimensions of the grid (rows and columns respectively).
  • An \(m \times n\) capacity matrix. The element in the \(i^{th}\) row and \(j^{th}\) column represents the maximum weight that the corresponding shelf can hold.
  • An \(m \times n\) weight matrix. The element in the \(i^{th}\) row and \(j^{th}\) column represents the weight of the product placed on that shelf.

The validity condition for each shelf cell can be expressed as:

[ weight_{ij} \leq capacity_{ij} ]

The input will continue with test cases until a line with "0 0" is encountered, which signals the end of input and should not be processed.

For each test case, output "VALID" if every shelf satisfies the condition above, or "INVALID" otherwise.

inputFormat

The input is read from stdin and is structured as follows:

  • The first line of each test case contains two integers \(m\) and \(n\) separated by a space.
  • The next \(m\) lines each contain \(n\) integers representing the capacity matrix.
  • The following \(m\) lines contain \(n\) integers each representing the weight matrix.
  • The sequence of test cases ends with a line containing "0 0". This line should not be processed.

outputFormat

For each test case processed, output a single line to stdout containing the result: "VALID" if the shelf arrangement is valid or "INVALID" if it is not.

If there are multiple test cases, each result should be printed on a new line.

## sample
2 3
5 10 7
8 6 5
4 6 7
3 3 3
0 0
VALID

</p>