Garden Informatization
Time limit2sMemory limit512 MB
Given a rectangle with up to 10 axis-aligned obstacle rectangles, place one or two non-overlapping axis-aligned beds to maximize total area.
- Level
Hard8 of 10
- Topics
- Geometry, Brute force, Implementation, Math
- Solved
- No attempts yet
Problem
Stepan Petrovich's garden plot is a rectangle of size . The plot contains buildings, and the base of each building is a rectangle with sides parallel to the sides of the plot.
Inspired by his neighbors' success, Stepan Petrovich wants to plant types of fruit crops on his plot (Stepan Petrovich's plot is in a northern region, so or ). For each crop type, Stepan Petrovich wants to allocate a separate rectangular bed with sides parallel to the sides of the plot. Naturally, the beds cannot occupy the territory occupied by buildings or other beds.
Stepan Petrovich wants to place the beds so that their total area is maximized. The beds must not intersect, but they may touch each other.

Given the dimensions of the plot and the coordinates of the buildings, determine the optimal placement of the beds.
Input
The first line of the input file contains two integers and (; ).
The second line contains two integers and ().
The next lines each contain four integers , the coordinates of two opposite corners of a building (, ). Different buildings cannot intersect, but they may touch each other.
Output
Output lines to the output file, each containing the coordinates of two opposite corners of a proposed bed. The coordinates must be integers (a placement maximizing the total area of the beds can always be achieved with rectangles of integer coordinates).
If in your solution Stepan Petrovich should plant fewer than beds, output the line "0 0 0 0" for the beds that should not be planted (see example 2).