Kingdom Partitioning
Time limit2sMemory limit128 MB
Simulate a sweep of vertical lines where each remaining kingdom's threshold crossing position is found via circle-area integration and the smallest threshold is served each round.
- Level
Medium6 of 10
- Topics
- Geometry, Simulation, Greedy
- Solved
- No attempts yet
Problem
The Kingdom of Qari has fallen, and other kingdoms are dividing its land. Each of them values a different part of Qari. Napaj wants open ground to settle on, while Acirema cares only about the oil fields.
Every kingdom marks the land it wants as a union of circles that do not overlap. Kingdom is content when the land it receives holds at least of the area it marked.
The council cuts Qari with vertical lines, that is, lines parallel to the axis. The lines split the land into strips, and each strip goes to one kingdom. The council draws the lines from left to right by the following rule.
Let be the position of the last line drawn, and let be at minus infinity before the first line. For every kingdom that holds no strip yet, take the smallest position such that the strip between and holds at least of the area kingdom marked. The council gives that strip to the kingdom with the smallest , draws the line at , and repeats with the remaining kingdoms. The kingdom left at the end takes everything to the right of the last line.
If several kingdoms share the smallest , the kingdom with the smaller number is served first. Two positions that differ by less than count as the same position.
This rule always serves all kingdoms, and every one of them ends up content. Print the order in which the kingdoms are served.
Input
The first line contains an integer (), the number of kingdoms dividing Qari. Then follow sections, one per kingdom, in the same order as the kingdom numbers.
The first line of the -th section contains an integer (), the number of circles marked by kingdom . Each of the next lines contains three integers , and (; ), the coordinates of the center of one circle and its radius. Circles inside one section do not overlap, but they may touch. Circles marked by different kingdoms may overlap in any way.
Output
Print integers on one line, separated by single spaces: the numbers of the kingdoms in the order they receive their strips, from left to right.
Note

The picture shows the circles marked in the first example. Kingdom 1 marked the two circles labeled 1' and 1'', and kingdom 2 and kingdom 3 both marked the circle labeled 2 and 3. The dashed lines are one fair division of the land, but not the division the council draws here, because the council only uses lines parallel to the axis.
Kingdom 1 marked in total and needs , which it reaches at , inside its left circle. Kingdom 2 and kingdom 3 each marked and need , which they reach at . Kingdom 1 therefore takes the first strip. Kingdom 2 and kingdom 3 are then tied, so the smaller number goes first, and kingdom 3 keeps everything to the right of the second line, two thirds of its circle.