#K42007. Find the First Peak in a Grid

    ID: 26991 Type: Default 1000ms 256MiB

Find the First Peak in a Grid

Find the First Peak in a Grid

You are given a grid of size \(n \times m\) where each cell contains an integer representing the height of a building. Your task is to identify a peak cell in this grid. A cell \( (i, j) \) is considered a peak if its value is greater than or equal to the values of its adjacent neighbors (up, down, left, and right). In this problem, you must return the first peak encountered in row-major order (i.e., the cell with the smallest row index, and among those, the smallest column index).

Note: If multiple cells satisfy the peak condition, the one that appears first while scanning the grid row by row (from top left to bottom right) should be output.

Example: For the grid

[ \begin{matrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & 8 & 9 \end{matrix} ]

the answer is 2 2 because the cell with value 9 is the first peak (and in this case, the only peak when scanning in order).

inputFormat

The first line contains two space-separated integers \(n\) and \(m\), representing the number of rows and columns respectively. Each of the following \(n\) lines contains \(m\) space-separated integers indicating the height of each building in that row.

outputFormat

Output two space-separated integers denoting the row index and column index (0-indexed) of the first peak cell found in the grid.

## sample
3 3
1 2 3
4 5 6
7 8 9
2 2