#K1386. Taco - Maximum Total Significance

    ID: 24006 Type: Default 1000ms 256MiB

Taco - Maximum Total Significance

Taco - Maximum Total Significance

You are given an \(N \times M\) grid where each cell contains an integer representing its height. A cell is considered a peak if none of its four adjacent neighbors (up, down, left, right) has a height greater than or equal to it. David wants to start a trip from a peak and move through cells by only stepping into an adjacent cell with a strictly higher height. The total significance of a trip is defined as the sum of the heights along the path. Your task is to compute the maximum total significance value that can be achieved in one such trip. If the grid is flat or no valid trip exists, output 0.

Note: Movement is allowed only to adjacent cells (sharing a side), and each move must go to a cell with a strictly greater height than the current one.

inputFormat

The first line of input contains two integers \(N\) and \(M\), representing the number of rows and columns, respectively.

The following \(N\) lines each contain \(M\) integers, where each integer represents the height in a cell of the grid.

outputFormat

Output a single integer denoting the maximum total significance value that can be achieved by starting at a peak and moving according to the rules.

## sample
3 3
1 2 1
3 4 3
1 8 1
8