#P5930. [POI 1999 R3] 降水

[POI 1999 R3] 降水

Problem Description

In a faraway place, there is a piece of land. It is divided into N×MN \times M square cells, each with an area of one square inch. The cell in row ii and column jj can be denoted as (i,j)(i,j). The land is uneven: each cell (i,j)(i,j) has its own height H(i,j)H(i,j) (in inches).

After a heavy rain, because of the differences in height, a lot of rainwater is stored in many low-lying areas. Suppose you already know the detailed information of this land. Can you compute the maximum number of cubic inches of rainwater it can store?

Input Format

The first line of the input file contains two numbers N,MN, M, meaning the land has size N×MN \times M square inches.

Then follow NN lines, each containing MM integers, giving the height of each cell (each integer is in [1,10000][1,10000], in inches).

Output Format

Output one integer in a single line, representing the maximum number of cubic inches of water that can be stored on the land.

3 6
3 3 4 4 4 2
3 1 3 2 1 4
7 3 1 6 4 1
5

Hint

For 100%100\% of the testdata, 1N,M1001 \le N, M \le 100.

Constraints

Translated by ChatGPT 5