P5930 [POI 1999 R3] Rainfall
Description
In a faraway place, there is a piece of land. It is divided into $N \times M$ square cells, each with an area of one square inch. The cell in row $i$ and column $j$ can be denoted as $(i,j)$. The land is uneven: each cell $(i,j)$ has its own height $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, M$, meaning the land has size $N \times M$ square inches.
Then follow $N$ lines, each containing $M$ integers, giving the height of each cell (each integer is in $[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.
Explanation/Hint
For $100\%$ of the testdata, $1 \le N, M \le 100$.
# Constraints
Translated by ChatGPT 5