#P10763. [BalticOI 2024] Tiles
[BalticOI 2024] Tiles
Background
Translated from BalticOI 2024 Day2 T2.
Problem Description
There is a cathedral with vertices, whose coordinates are in order. For each , there is an edge between and . In addition, there is an edge between and .
Each edge of the cathedral is parallel to the axis or the axis. Also, the cathedral is a simple polygon, meaning that:
- Each vertex is incident to exactly two edges.
- Any pair of edges can intersect only at a vertex.
You have infinitely many tiles, and you want to use these tiles to cover most of the cathedral region. More precisely, you want to choose a vertical line and cover the part of the cathedral to the left of that line. For any integer , let be the vertical line that contains the points with coordinate equal to . Covering the part of the cathedral to the left of means placing some tiles on the plane such that:
- Every point inside the polygon with coordinate less than is covered by some tile.
- No point outside the polygon, or with coordinate greater than , is covered by any tile.
- The interiors of the tiles do not overlap.
The minimum coordinate among all vertices of the cathedral is . Let be the maximum coordinate among all vertices of the cathedral.
Please find the maximum that satisfies the conditions. By definition, an answer of always exists.
Input Format
The first line contains two integers .
The next lines each contain two integers . The vertices are given in clockwise or counterclockwise order.
Output Format
Output the answer .
14 6
0 1
0 3
2 3
2 4
0 4
0 6
3 6
3 7
4 7
6 7
6 5
3 5
3 2
3 1
2
4 3
0 0
0 3
3 3
3 0
0
18 9
0 2
2 2
2 1
4 1
4 0
9 0
9 2
4 2
4 4
7 4
7 3
9 3
9 6
4 6
4 5
2 5
2 4
0 4
6
Hint
| Subtask ID | Special Property | Score |
|---|---|---|
| ,for , | ||
| and | ||
| All are even | ||
| All are even | ||
| No special property |
For all testdata, , , , .
For Sample 1, below is the covering for .

You can see that this is the largest possible case.
For Sample 2, there is no positive such that the part of the cathedral to the left of can be covered with tiles.
For Sample 3, the diagram is as follows.

Translated by ChatGPT 5