#P2219. Maximizing Green Belt Fertility
Maximizing Green Belt Fertility
Maximizing Green Belt Fertility
In a park modeled as an $M\times N$ rectangle, we plan to construct a flower bed and surround it with a green belt. The flower bed is a $C\times D$ rectangle, and together with the green belt, they form an $A\times B$ rectangle, which is embedded in the park.
The fertility of any rectangular piece of land is defined as the sum of the fertilities of all its unit cells. Thus, the fertility of the green belt is the fertility of the entire $A\times B$ rectangle minus that of the $C\times D$ flower bed inside it. In order to make the green belt flourish, we wish to maximize its fertility.
You are given the park as a matrix of integers where each cell represents the fertility value of that unit land. Your task is to choose the position of an $A\times B$ rectangle within the park, and inside it, choose the position of a $C\times D$ rectangle representing the flower bed. The green belt is defined as the difference between the sum of the $A\times B$ region and the sum of the $C\times D$ region (i.e. green belt fertility = sum($A\times B$) - sum($C\times D$)). Compute the maximum possible green belt fertility.
Note: The $C\times D$ rectangle must lie entirely inside the $A\times B$ rectangle, and the $A\times B$ rectangle must lie entirely within the park.
inputFormat
The input begins with a line containing two integers $M$ and $N$, representing the dimensions of the park.
Next follow $M$ lines, each containing $N$ integers which denote the fertility values of the park's cells.
The last line contains four integers $A$, $B$, $C$, $D$ as described in the problem.
Constraints: It is guaranteed that $1 \leq C \leq A \leq M$ and $1 \leq D \leq B \leq N$.
outputFormat
Output a single integer, which is the maximum possible fertility of the green belt.
sample
3 3
1 2 3
4 5 6
7 8 9
2 2 1 1
23