#K42697. Valid Rainbow Pattern Checker
Valid Rainbow Pattern Checker
Valid Rainbow Pattern Checker
You are given a grid of size \(n \times m\) filled with integers. Your task is to determine whether the grid forms a valid rainbow pattern. The grid is said to form a valid rainbow pattern if:
- Every row is in non-decreasing order.
- Every column is in non-decreasing order.
- The grid contains all distinct integers from \(1\) to \(n \times m\) exactly once.
Print YES
if all conditions are satisfied, otherwise print NO
.
Note: The input is provided via stdin
and the output must be printed to stdout
.
inputFormat
The first line contains two integers \(n\) and \(m\), representing the number of rows and columns respectively. The following \(n\) lines each contain \(m\) space-separated integers representing the grid.
It is guaranteed that \(1 \leq n, m \leq 100\) and the integers in the grid are between \(1\) and \(n \times m\).
outputFormat
Output a single line containing YES
if the grid forms a valid rainbow pattern, otherwise output NO
.
4 3
1 2 3
4 5 6
7 8 9
10 11 12
YES