#P3625. [APIO2009] 采油区域

[APIO2009] 采油区域

Description

The Siruseri government has decided to auction off land in the oil-rich province of Navalur to private contractors for building oil wells. The land to be auctioned is a rectangular area divided into M×NM \times N blocks. The Siruseri Geological Survey has estimates of the oil reserves in Navalur. These are given as M×NM \times N positive integers, i.e., the estimated yield for each block.

To avoid monopoly, the government stipulates that each contractor may lease only one square region consisting of K×KK \times K adjacent blocks. The AoE Oil Consortium consists of three contractors. They want to choose three pairwise non-overlapping K×KK \times K regions so that the total yield is maximized.

For example, suppose the estimated yields are as follows:

1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 
1 8 8 8 8 8 1 1 1 
1 8 8 8 8 8 1 1 1 
1 8 8 8 8 8 1 1 1 
1 1 1 1 8 8 8 1 1 
1 1 1 1 1 1 8 8 8 
1 1 1 1 1 1 9 9 9 
1 1 1 1 1 1 9 9 9 
  • If K=2K = 2, the total yield the AoE company can get is 100100.
  • If K=3K = 3, the total yield the AoE company can get is 208208.

AoE hires you to write a program to compute the maximum possible sum of yields of the regions they can lease.

Input Format

The first line contains three positive integers MM, NN, KK, where MM and NN are the numbers of rows and columns of the rectangle, and KK is the side length (in blocks) of each contractor’s square region. The next MM lines each contain NN positive integers giving the estimated yield for each block in that row.

Output Format

Output a single integer: the maximum possible total yield of the three leased regions.

9 9 3
1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 
1 8 8 8 8 8 1 1 1 
1 8 8 8 8 8 1 1 1 
1 8 8 8 8 8 1 1 1 
1 1 1 1 8 8 8 1 1 
1 1 1 1 1 1 8 8 8 
1 1 1 1 1 1 9 9 9 
1 1 1 1 1 1 9 9 9 
208

Hint

It is guaranteed that KMK \le M and KNK \le N, and that there exist at least three pairwise disjoint K×KK \times K square regions.

For 30%30\% of the testdata, M,N12M, N \le 12. For all testdata, M,N1500M, N \le 1500. The estimate for each block is a non-negative integer not exceeding 500500.

Translated by ChatGPT 5