Planting Trees
Time limit: C / C ++ 3 seconds to 6 seconds languages other
space restrictions: C / C ++ 262144K, other languages 524288K
64bit IO the Format:% LLD
space restrictions: C / C ++ 262144K, other languages 524288K
64bit IO the Format:% LLD
Title Description
The semester is finally over and the summer holiday is coming. However, as part of your university's graduation requirement, you have to take part in some social service during the holiday. Eventually, you decided to join a volunteer group which will plant trees in a mountain.
To simplify the problem, let's represent the mountain where trees are to be planted with an
N×N grid. Let's number the rows 1 to N from top to bottom, and number the columns 1 to N from left to right. The elevation of the cell in the i-th row and j-th column is denoted by ai,j. Your leader decides that trees should be planted in a rectangular area within the mountain and that the maximum difference in elevation among the cells in that rectangle should not exceed M. In other words, if the coordinates of the top-left and the bottom-right corners of the rectangle are (x1,y1) and (x2,y2), then the condition ∣ai,j−ak,l∣≤M must hold for x1≤i,k≤x2, y1≤j,l≤y2