#P11774. Maximizing Overlapping Rectangles
Maximizing Overlapping Rectangles
Maximizing Overlapping Rectangles
You are given (N) axis-aligned and non-overlapping rectangles in the plane, each described by the coordinates of its bottom-left corner ((x_1, y_1)) and top-right corner ((x_2, y_2)). In addition, you have a rectangle (S) of fixed dimensions: width (W) and height (H). You can place (S) anywhere (its vertices are not required to lie on integer coordinates). Your goal is to choose a placement for (S) so that the number of given rectangles that (S) intersects is maximized. Two rectangles are said to intersect if their overlapping area is strictly greater than zero.
The rectangle (S) placed at position ((X, Y)) (with bottom-left corner at ((X,Y)) and top-right at ((X+W, Y+H))) intersects a given rectangle ((x_1,y_1,x_2,y_2)) if and only if: [ X < x_2, \quad X+W > x_1, \quad Y < y_2, \quad Y+H > y_1. ]
Determine the maximum number of rectangles that can be intersected by an optimally placed rectangle (S).
inputFormat
The first line of input contains three numbers: (N), (W), (H) (where (N) is an integer, and (W) and (H) are numbers). Each of the next (N) lines contains four numbers (x_1), (y_1), (x_2), (y_2) representing a rectangle with bottom-left coordinate ((x_1, y_1)) and top-right coordinate ((x_2, y_2)).
outputFormat
Output a single integer: the maximum number of rectangles that a rectangle (S) with dimensions (W \times H) can intersect if placed optimally.
sample
3 2 2
0 0 2 2
1 1 3 3
4 4 6 6
2