Tiles
시간 제한2초메모리 제한1024 MB
축에 평행한 단순 다각형이 주어질 때, x < k인 다각형 내부 영역을 겹치지 않는 2 곱하기 2 정사각형으로 정확히 덮을 수 있는 가장 큰 정수 k를 구한다.
문제
Soon after converting to Christianity, it is believed that the first and the only Lithuanian King Mindaugas ordered the construction of the Vilnius Cathedral. The construction is almost completed, except that the floor has to be covered with ceramic ornamented glazed tiles.
The floor of the Vilnius Cathedral is a polygon in a 2D plane with a Cartesian coordinate system. The polygon has distinct vertices, numbered from to . For each such that , vertex is located at point , where and are nonnegative integers. There is an edge connecting vertex and vertex (for each such that ), as well as an edge connecting vertex and vertex . The vertices are listed in either clockwise or counterclockwise order.
The cathedral is an axis-aligned polygon, which means that each of the edges is parallel to either the -axis or the -axis. Moreover, the cathedral is a simple polygon, that is:
- exactly two edges meet at each vertex;
- any pair of edges can only meet at a vertex.
The builders of the cathedral have infinitely many pieces of tiles. Each piece is a square with side length equal to . The builders would like to cover a big part of the cathedral with these pieces. Specifically, the builders want to pick some vertical line and cover the part of the cathedral to the left of the line. For any integer , let denote the vertical line consisting of points with -coordinate equal to . A covering of the part of the cathedral to the left of is a placement of some number of pieces in the plane such that:
- each point which lies in the interior of the polygon and has -coordinate less than is covered by some piece;
- no point which lies outside of the polygon or has -coordinate greater than is covered by some piece;
- the interiors of the pieces do not overlap.
The minimum -coordinate of any vertex in the cathedral is . Let denote the maximum -coordinate of any vertex in the cathedral.
Help the builders of the Vilnius Cathedral by determining the largest integer , such that , and there exists a covering of the part of the cathedral to the left of . Note that by definition, there exists a covering of the part of the cathedral to the left of (which uses pieces).
입력
The first line of the input contains two integers and – the number of vertices and the maximum -coordinate of any vertex.
Then, lines follow. The -th of them contains two integer numbers and – the coordinates of -th vertex. The vertices are listed in either clockwise or counterclockwise order.
출력
Your program should output the maximum , such that and there exists a covering of the part of the cathedral to the left of .
제한
- (for each )
- The cathedral forms an axis-aligned simple polygon.
- The minimum of is , and the maximum of is .