#C9956. Find Peak Elevation
Find Peak Elevation
Find Peak Elevation
You are given a matrix that represents a mountain range, where each cell contains an integer indicating the elevation at that point. A cell is considered a peak if and only if its elevation is greater than or equal to the elevations of its four directly adjacent neighbors (up, down, left, and right). In other words, a cell \(a_{ij}\) is a peak if it satisfies:
[ a_{ij} \geq a_{i-1,j}, \quad a_{ij} \geq a_{i+1,j}, \quad a_{ij} \geq a_{i,j-1}, \quad a_{ij} \geq a_{i,j+1} ]
If there are multiple peaks, output the highest peak value. In the special case where no cell qualifies as a peak (which might occur in degenerate situations), return the elevation of the top-left corner of the matrix.
Note: The neighbors that are out-of-bound are not considered; only compare with existing neighbors.
inputFormat
The first line of input contains two space-separated integers \(r\) and \(c\) -- the number of rows and columns of the matrix, respectively. The following \(r\) lines each contain \(c\) space-separated integers representing the elevation values of the matrix.
outputFormat
Output a single integer: the maximum peak elevation found in the matrix.
## sample3 3
1 2 3
6 5 4
7 8 9
9