
ZOJ Problem Set  2798
After building his huge villa, Mr. Rich cannot help but notice that the interior walls look rather blank. To change that, he starts to hang paintings from his wonderful collection. But soon he realizes that it becomes quite difficult to find a place on the wall where a painting can be placed without overlapping other paintings. Now he needs a program which would tell him, given the already placed paintings, where to place the next painting without moving any other paintings (or indicating that this is impossible). Paintings have a rectangular shape and are to be placed parallel to the side of the wall. If you do not mind a nice reward from Mr. Rich, go on and solve the problem. Input Specification The first line of the input file contains a number representing the
number of test cases to follow.
Each test case starts with a line containing three numbers n,
w
and h.
n is the number of paintings already hanging on the
wall, w
is the width of the wall
and h is the height of the wall.
The next n lines contain 4 integers x_{1}, y_{1},
x_{2}, y_{2} each (0 ≤ x_{1} < x_{2} ≤ w,
0 ≤ y_{1} < y_{2} ≤ h); the
xcoordinates give
the distance to the left end of the wall, the ycoordinates give the
distance to the bottom of the wall.
(x_{1}, y_{1}) is the position of the lower left corner of a painting,
(x_{2}, y_{2})
is the position of the upper right corner.
The last line of each test case contains the dimensions of the next
painting
to be placed, first its width w', then its height h' (1 ≤ w' ≤ w, 1 ≤ h' ≤ h).
You are not allowed to rotate the painting.
Output Specification Produce one line of output for each test case. Write "Fail!" if there is no place left on the wall where the painting could be placed without overlapping other paintings. Otherwise, write the coordinates where the lower left corner of the painting should be placed. In case there is more than one solution, select the solution with a minimum ycoordinate, and break ties using the minimum xcoordinate.
Source: University of Ulm Local Contest 2005 