Digging for Oil
Time limit2sMemory limit128 MB
Place three non-overlapping K by K squares on an M by N grid of oil estimates to maximize the total sum covered, with the grid up to 1500 by 1500.
- Level
Hard8 of 10
- Topics
- Prefix sum, Dynamic programming, Array, Implementation
- Solved
- No attempts yet
Problem
The government of Siruseri has decided to auction off, to oil-development contractors, the land of Navaru province where crude oil is abundant. The whole area up for auction is divided into small blocks that form an rectangular grid.
Siruseri's geological survey bureau has an estimate of the crude-oil content of each block; these estimates are given as a non-negative integer in each cell of the grid.
To prevent monopolies, the government requires that each contractor may bid on exactly one contiguous square of blocks.
The AoE Oil Association, made up of three contractors, wants to secure as much oil as possible by choosing three non-overlapping square regions.
For example, for the grid in the sample input below, the best achievable total is when and when .
Write a program that finds the maximum total estimated oil content the AoE Association can secure.
Input
The first line contains three integers , , and , where and are the numbers of rows and columns of the grid, and is the side length of the square region a contractor bids on. Each of the next lines contains the oil-content estimates of the blocks in one row, given as non-negative integers.
and , and at least three non-overlapping regions exist. Also , and every block's estimate is a non-negative integer less than .
Output
Print, on a single line, the maximum total estimated oil content the AoE Oil Association can secure.