Tiles

시간 제한2초메모리 제한1024 MB

요약
축에 평행한 단순 다각형이 주어질 때, x < k인 다각형 내부 영역을 겹치지 않는 2 곱하기 2 정사각형으로 정확히 덮을 수 있는 가장 큰 정수 k를 구한다.
난이도

어려움10점 중 8점

유형
기하, 그리디, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

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 NN distinct vertices, numbered from 11 to NN. For each ii such that 1≤i≤N1 ≤ i ≤ N, vertex ii is located at point (X\[i],Y\[i])(X\[i],Y\[i]), where X\[i]X\[i] and Y\[i]Y\[i] are nonnegative integers. There is an edge connecting vertex ii and vertex i+1i + 1 (for each ii such that 1≤i≤N−11 ≤ i ≤ N - 1), as well as an edge connecting vertex NN and vertex 11. 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 xx-axis or the yy-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 22. 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 kk, let L_kL\_k denote the vertical line consisting of points with xx-coordinate equal to kk. A covering of the part of the cathedral to the left of L_kL\_k 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 xx-coordinate less than kk is covered by some piece;
  • no point which lies outside of the polygon or has xx-coordinate greater than kk is covered by some piece;
  • the interiors of the pieces do not overlap.

The minimum xx-coordinate of any vertex in the cathedral is 00. Let MM denote the maximum xx-coordinate of any vertex in the cathedral.

Help the builders of the Vilnius Cathedral by determining the largest integer kk, such that k≤Mk ≤ M, and there exists a covering of the part of the cathedral to the left of L_kL\_k. Note that by definition, there exists a covering of the part of the cathedral to the left of L_0L\_0 (which uses 00 pieces).

입력

The first line of the input contains two integers NN and MM – the number of vertices and the maximum xx-coordinate of any vertex.

Then, NN lines follow. The ii-th of them contains two integer numbers x_ix\_i and y_iy\_i – the coordinates of ii-th vertex. The vertices are listed in either clockwise or counterclockwise order.

출력

Your program should output the maximum kk, such that k≤Mk ≤ M and there exists a covering of the part of the cathedral to the left of L_kL\_k.

제한

  • 4≤N≤2⋅1054 ≤ N ≤ 2 \cdot 10^5
  • 1≤M≤1091 ≤ M ≤ 10^9
  • 0≤y_i≤1090 ≤ y\_i ≤ 10^9 (for each 1≤i≤N1 ≤ i ≤ N)
  • The cathedral forms an axis-aligned simple polygon.
  • The minimum of x_1,x_2,…,x_Nx\_1 ,x\_2 , \dots ,x\_N is 00, and the maximum of x_1,x_2,…,x_Nx\_1 ,x\_2 , \dots ,x\_N is MM.

예제3

  1. 예제 1

    입력
    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
    
  2. 예제 2

    입력
    4 3
    0 0
    0 3
    3 3
    3 0
    
    예상 출력
    0
    
  3. 예제 3

    입력
    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