#t148. 建造停机坪
建造停机坪
Building a Helipad
Problem Description
Xiao A has a terrain map with rows and columns, where the number at row , column represents the altitude at coordinates .
A helipad is a region whose points have a maximum-to-minimum altitude difference of at most .
Xiao A asks you to compute, among all regions suitable for building a helipad, the maximum possible sum of the altitudes of the points inside the region.
Input Format
The first line contains three positive integers , as described.
The following lines: the -th line contains integers , the altitudes at coordinates .
It is guaranteed that at least one region suitable for building a helipad exists.
Output Format
Output one line containing the maximum sum of altitudes.
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 spanning rows to and columns to satisfies the condition. Its altitudes are:
- Row 3: ;
- Row 4: ;
- Row 5: .
Their sum is . The maximum altitude in the region is and the minimum is , so the altitude difference is , which does not exceed . It can be verified that this is the largest altitude sum among all valid regions, so the output is .
Constraints
For all test cases, and are guaranteed.