Luxury burrow
Time limit2sMemory limit64 MB
Find the rectangle of area at least K whose minimum cell price is largest, breaking ties by larger area.
- Level
Medium7 of 10
- Topics
- Binary search, Stack, Matrix
- Solved
- No attempts yet
Problem
The hobbit Bilbo is worn out from his adventures and has decided to build a new burrow. The hill where he plans to buy land is a rectangle, and it can be written as a table with rows and columns. Rows and columns are numbered from 1, where row 1 is the topmost row and column 1 is the leftmost column. Each cell of the table is one piece of land. Hobbits like simple shapes, so Bilbo buys a rectangular plot whose sides are parallel to the sides of the hill. He picks , , , with and , then buys every cell with and .
After his adventures Bilbo is rich, so the total price does not worry him. His reputation does, so the price of the cheapest cell he buys must be as high as possible. The burrow also has to hold all of his furniture, so the area of the plot must be at least . If several plots satisfy both conditions, Bilbo takes the one with the largest area.
Find the best plot for Bilbo.
Input
The first line contains the integers , and , separated by one space each: the number of rows, the number of columns, and the smallest area Bilbo can live on. Each of the next lines contains integers. The -th number on line is the price of cell .
and are positive integers not greater than , is a positive integer not greater than the total number of cells, and every price is between and , inclusive.
Output
Print two integers on one line, separated by a single space. The first is the price of the cheapest cell in the chosen plot. The second is the area of that plot.