#C10319. Grid Path Finder
Grid Path Finder
Grid Path Finder
You are given a grid with m rows and n columns. Each cell in the grid contains an integer value. Your task is to determine if there exists a valid path from the top-left corner to the bottom-right corner.
You can only move in two directions: right or down. However, you can only move from a cell with value \(A_{i,j}\) to an adjacent cell if the value of the target cell is not less than \(A_{i,j}\) (i.e. \(A_{next} \geq A_{current}\)).
If such a path exists, output YES
; otherwise, output NO
.
inputFormat
The input is given via standard input and has the following format:
The first line contains two integers m
and n
separated by a space.
This is followed by m
lines, each containing n
space-separated integers representing the grid.
outputFormat
Output a single string to the standard output: either YES
if there exists a valid path based on the rules, or NO
if no such path exists.## sample
3 3
1 2 3
6 5 2
7 6 8
YES