ACM Midatlantic programming contest 2014, Problem E Thoughts: Alg 1: Make a 2 dim array the size of the backing cloth initialized to zero. For each rectangle, add one to each square it covers. At the end scan the array for the square with the highest number. However, this is probably too expensive. How expensive is it? ...there are 10 billion squares (10^5 x 10^5). ...There are 1000 rectangles of size up to 10 billion squares each. ---------------------- For the corners, x1 y1 x2 y2, I'm going to assume x1 < x2 and y1 < y2. The problem statement doesn't make this clear, but it's that way in the examples. ... Could easily convert to this form in any case. ---------------------- Alg2 sketch: Segment (partition) the backing into rectangles of constant thickness (of covering rectangles). For each new rectangle in turn, update this segmentation. Needed: a good way to determine which segments interact with the new rectangle. Sorting by x coord and by y coord may help. ...possibly 4 sorted sequences: by x and y coord of lower left corner and by x and y coord of upper right corner. ---------------------- Detecting overlap: Define less-than this way, (u,v) < (x,y) if u < x and v < y. Then two rectangles A,B overlap iff SW(A) < NE(B) and SW(B) < NW(A). Here SW and NW refer to the south west and north east corner points respectively. ---------------------- Ideas considered. A. Store layers of non-overlapping rectangles. Go through the rectangles putting them in the layers in first fit fashion. Count number of layers used. Unfortunately a counter example can be found for this first fit strategy. B. Form graph where vertices are the rectangles and two vertices have an edge if the rectangles overlap. Find a maximal clique in this graph. Geometrical theorem: If n rectangles overlap pairwise (each of the n choose 2 has overlap) then there is a square where they all overlap.