Secure Region
Time limit1sMemory limit128 MB
Given an axis-aligned field and up to 300 mines, find the axis-aligned mine-free rectangle with the largest shorter side, then the largest longer side.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search, Sorting, Brute force
- Solved
- No attempts yet
Problem
A minefield is given as an axis-aligned bounding rectangle together with the positions of all mines inside it. A helicopter must land on the most secure region: an axis-aligned rectangle that lies within the field, contains no mine in its interior, and whose shorter side is as long as possible.
Formally, consider every axis-aligned rectangle inside the field that contains no mine in its interior. Let its side lengths be and with . The most secure region is the one with the largest possible ; among all rectangles achieving that largest , it is the one with the largest .
A mine lying exactly on an edge or corner (the boundary) of a rectangle does not count as being inside it.
Given the bounding rectangle of the field and the positions of all mines, compute the two side lengths of the most secure region.
Input
The input consists of several minefields.
Each minefield is described as follows. The first line contains four integers , , , , where is the lower-left corner and the upper-right corner of the field ( and ). The next line contains an integer (), the number of mines. Each of the following lines contains two integers and , the position of a mine ( and ). No two mines share the same position.
The input ends with a line where ; this line is not processed.
Output
For each minefield, print one line with two integers and (): the two side lengths of the most secure region.