#P2219. [HAOI2007] 修筑绿化带

    ID: 1193 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2007河南各省省选平衡树单调队列队列

[HAOI2007] 修筑绿化带

Description

To enhance the park’s scenery, we need to build a flowerbed in the park and, around the flowerbed, construct a green belt so that the flowerbed is enclosed by the green belt.

If we regard the park as an M×NM\times N rectangle, then the flowerbed can be regarded as a C×DC\times D rectangle, and the green belt together with the flowerbed can be regarded as an A×BA\times B rectangle.

If we define the fertility of a rectangular land region as the sum of the fertility values of all unit cells within that region, then the fertility of the green belt equals the fertility of the A×BA\times B block minus the fertility of the C×DC\times D block.

To make the green belt grow vigorously, we want the fertility of the green belt to be maximized.

Input Format

The first line contains six positive integers M,N,A,B,C,DM,N,A,B,C,D.

Then follows an M×NM\times N numeric matrix. The element in row ii and column jj is an integer xi,jx_{i,j}, representing the fertility of the land at row ii and column jj of the park.

Output Format

Output a single positive integer, the maximum fertility of the green belt.

4 5 4 4 2 2
20 19 18 17 16
15 14 13 12 11
10 9 8 7 6
5 4 3 2 1

132

Hint

For 30%30\% of the testdata, 1M,N501\leq M,N\leq 50.

For 100%100\% of the testdata, 1M,N10001\leq M,N\leq 1000, 1AM1\leq A\leq M, 1BN1\leq B\leq N, 1CA21\leq C\leq A-2, 1DB21\leq D\leq B-2, 1xi,j1001\leq x_{i,j}\leq 100.

Translated by ChatGPT 5