Land Inheritance
Time limit10sMemory limit512 MB
Given an H by W grid of prices, split it into N non-overlapping rectangles so that the smallest rectangle sum is as large as possible, and report that sum.
- Level
Medium7 of 10
- Topics
- Binary search, Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
A family of brothers is dividing the vast land left by their parents. The land is a rectangle km from north to south and km from west to east. It is managed in 1 km square cells. The cell that lies from to km from the north edge and from to km from the west edge is called cell , where and are integers with and . Each cell has a price, and the price of cell is .
The brothers divide the land as follows.
- Each brother chooses some cells and inherits them.
- The cells each brother inherits must form one rectangle.
- The land inherited by the brothers must not overlap.
- Some cells may go to nobody. Those cells are abandoned.
The price of a brother's land is the sum of the prices of the cells in that brother's rectangle. The brothers want the prices to be as fair as possible. Find the division that maximizes the lowest land price among the brothers, and print that lowest price.
Input
The input is given in the following format.
H W N
a_{0,0} a_{0,1} ... a_{0,W-1}
...
a_{H-1,0} a_{H-1,1} ... a_{H-1,W-1}
and () are the north-south and east-west lengths of the land. () is the number of brothers. () is the price of cell .
Output
Print the lowest land price on one line when the land is divided to maximize that price.