ENIGMA-0x03 (2025) - A2 Sharing Chocolate
View as PDFSharing Chocolate

George loves chocolate, so he bought a large rectangular bar to share with his family.
While absentmindedly watching TV, he carelessly cut out and ate several rectangular pieces from the interior of the chocolate. Now George is left with a large rectangular chocolate bar that may contain several rectangular holes. These holes may overlap, creating more complex empty regions inside the chocolate.
George wants to divide the remaining chocolate among the K members of his family using K - 1 vertical cuts, so that the resulting pieces have areas as equal as possible.
He asked for your help to find the x-coordinates of the vertical cuts that divide the chocolate into K strips of equal area.
Input
The first line contains four real numbers
x1 y1 x2 y2: the coordinates of the bottom-left () and top-right (
) corners of the original rectangular chocolate bar.
The second line contains an integer M: the number of rectangular pieces that George has already eaten.
Each of the next M lines contains four real numbers
a b c d: the coordinates of the bottom-left () and top-right (
) corners of the i-th rectangular piece that was removed.
The last line contains an integer K: the number of family members.
Constraints
`
Output
Print K - 1 real numbers, each corresponding to the x-coordinate of a vertical cut.
The numbers must:
- be printed in increasing order
- divide the remaining chocolate into K pieces of equal area
Scoring
Your solution will be tested on the following subtasks:
| Subtasks | Points | Constraints |
|---|---|---|
| 1 | 2 | M = 0 |
| 2 | 3 | M = 1 |
| 3 | 5 | M = 2, no overlap between the internal rectangles |
| 4 | 8 | M = 2 |
| 5 | 15 | M ≤ 10³, no overlap |
| 6 | 17 | M ≤ 10³ |
| 7 | 20 | M ≤ 10⁵, no overlap |
| 8 | 30 | M ≤ 10⁵ |
A solution is considered correct for a test case if the relative error of each cut compared to the expected cut is at most .
Examples
Input (STDIN)
0 0 9 7
4
2 2 8 3
3 1 5 6
6 4 7 6
1 4 2 5
3
Output (STDOUT)
2.38888889
6.41666667
Input (STDIN)
0 0 10 10
2
2 2 7 8
5 5 9 9
4
Output (STDOUT)
1.50000000
4.50000000
8.16666667
Explanation of the second example:

Comments