Coloring Rectangles
Time limit2sMemory limit128 MB
Given N rectangles, choose exactly K of them to maximize the total visible union area under a max-index-wins overlap rule, picking the lexicographically smallest tie-break.
- Level
Hard9 of 10
- Topics
- Geometry, Dynamic programming, Combinatorics, Greedy
- Solved
- No attempts yet
Problem
There are N axis-aligned rectangles on a two-dimensional coordinate plane. The rectangles are numbered from 1 to N. Rectangle i has lower-left corner (x_i,1, y_i,1) and upper-right corner (x_i,2, y_i,2).
Choose exactly K of the N rectangles to color. If a region is covered by one or more rectangles, only the rectangle with the largest number among those covering that region is visible. The colored area is the total visible area belonging to the chosen rectangles. Find a choice that maximizes the colored area.
Input
The first line contains two integers N and K.
Each of the next N lines contains four integers x_i,1, y_i,1, x_i,2, and y_i,2, describing one rectangle.
Output
Print the numbers of the K rectangles to color, in increasing order, separated by spaces. If several choices maximize the colored area, print the lexicographically smallest sequence.
Constraints
1 <= K <= N <= 50-10000 <= x_i,1, y_i,1, x_i,2, y_i,2 <= 10000x_i,1 < x_i,2y_i,1 < y_i,2