#t149. 建造停机坪
建造停机坪
Building a Helipad
Problem Description
Little A has a terrain map of rows and columns, where the number at row , column is the altitude at coordinate .
A helipad is a region whose cells have a difference between the maximum and minimum altitude of at most .
Little A asks you to compute, among all regions suitable for a helipad, the maximum possible sum of the altitudes inside the region.
Input Format
The first line contains three positive integers , , and , as described. The following lines: the -th line contains integers , the altitudes at each coordinate. It is guaranteed that at least one helipad-suitable region exists.
Output Format
Output one line: the maximum altitude sum.
Sample Input
5 5 3
5 5 5 5 5
5 1 5 1 5
5 5 5 5 5
5 2 5 2 5
3 5 5 5 2
Sample Output
40
Sample Explanation
Among all regions, the one from row column to row column satisfies the condition. Its altitudes are:
row : ; row : ; row : .
Their sum is . The maximum altitude in the region is , the minimum is , the difference is , which does not exceed . It can be verified that this is the largest altitude sum among all valid regions, so the answer is .
Constraints
For all test points, , .