#P15197. [SWERC 2018] Blurred Pictures

[SWERC 2018] Blurred Pictures

题目描述

Damon loves to take photos of the places he visits during his travels, to put them into frames. All of his photos are in a square format of N×NN \times N pixels. He brought back beautiful pictures of the many monuments in Paris, such as the Eiffel Tower or the Louvre, but unfortunately, when he got back home, he realized that all his pictures were blurred on the “good” (i.e., non-blurred) ones and that, luckily, all the non-blurred pixels are connected in such a way that any horizontal or vertical line drawn between two non-blurred pixels goes only through non-blurred pixels. In order to get the best from his failed pictures, he decides to cut out the biggest possible picture without any blurred pixel from each of his photos. And since his frames are all squares, for aesthetic reasons, the cut-out pictures have to be squares too. Damon does not want his pictures to be tilted so he wants the sides of the cut-outs to be parallel to the sides of the original picture.

Important Note

  • In the input picture, each row and each column has at least one non-blurred pixel.
  • In any two consecutive lines, there are at least two non-blurred pixels in the same column.

输入格式

The input comprises several lines, each consisting of integers separated with single spaces:

  • The first line contains the length NN, in pixels, of the input photo;
  • Each of the next NN lines contains two integers aia_i and bib_i, the indices of the first (aia_i) and the last (bib_i) non-blurred pixel on the ii-th line.

输出格式

The output should consist of a single line, whose content is an integer, the length of the largest square composed of non-blurred pixels inside the picture.

3
1 1
0 2
1 1
1
8
2 4
2 4
1 4
0 7
0 3
1 2
1 2
1 1
3

提示

Limits

  • 0<N1000000 < N \leq 100\,000;
  • 0aibi<N0 \leq a_i \leq b_i < N.