#K85232. Peak Element in a Matrix
Peak Element in a Matrix
Peak Element in a Matrix
You are given a matrix of size M x N containing integers. An element \(a_{i,j}\) in the matrix is called a peak if it is not smaller than its available neighbors, that is, it satisfies:
[ \begin{aligned} a_{i,j} &\ge a_{i-1,j} \quad (\text{if } i-1 \ge 0),\ a_{i,j} &\ge a_{i+1,j} \quad (\text{if } i+1 < M),\ a_{i,j} &\ge a_{i,j-1} \quad (\text{if } j-1 \ge 0),\ a_{i,j} &\ge a_{i,j+1} \quad (\text{if } j+1 < N). \end{aligned} ]
Your task is to find and output any one peak element from the matrix. It is guaranteed that the matrix contains at least one element and hence at least one peak.
inputFormat
The input is given via stdin and has the following format:
- The first line contains two space-separated integers M and N, denoting the number of rows and columns of the matrix respectively.
- The next M lines each contain N space-separated integers representing the rows of the matrix.
outputFormat
Print to stdout a single integer, which is the value of any peak element found in the matrix.
## sample3 3
1 4 3
6 7 8
9 2 5
8