시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB72333145.588%

문제

Anna just came home from her favourite furniture store Ikey Yeah! where she bought a new bookshelf designed by her favourite artist Bill Lee. The shelf has a rectangular shape with a width of $x$ and a height of $y$. Included in the box of the shelf is one board that Anna may put horizontally inside the shelf. For this purpose the frame of the shelf already contains pre-drilled holes at heights $1,2,\ldots,y-1$. Anna may attach the board to the frame at any of these heights. She can also decide not to install it at all.

Anna owns $n$ books, which all have the same depth. The books' depth matches that of the shelf exactly. However, due to differences in the formats and the numbers of pages, her books may have different widths and heights. Anna does not want to flip her books or stack several of them on top of each other. Instead, she wants to store all of them in an upright fashion inside her bookshelf, such that the width and height of each book are aligned with the width and height of the bookshelf. Help Anna to find the perfect position for the board (or tell her not to use it at all) so that she can store all her books in her new bookshelf.

For this problem you may assume that the frame and the board of the shelf are infinitely thin.

입력

The input consists of:

  • One line with three integers $n$, $x$ and $y$, where 
    • $n$ ($1 \le n \le 10^4$) is the number of books that Anna owns;
    • $x$ ($1 \le x \le 10^4$) is the width of the bookshelf frame;
    • $y$ ($1 \le y \le 10^4$) is the height of the bookshelf frame.
  • $n$ lines, the $i$th of which contains two integers $w_i$ and $h_i$, where
    • $w_i$ ($1 \le w_i \le 10^4$) is the width of the $i$th book;
    • $h_i$ ($1 \le h_i \le 10^4$) is the height of the $i$th book.

출력

If there is no possibility to store Anna's books in the shelf, print out impossible. In case Anna decides not to install the board, output $-1$. Otherwise, output the height at which the board should be installed. If there are multiple possible heights, you may output any one of them.

예제 입력 1

4 4 4
3 1
1 1
1 3
2 2

예제 출력 1

3

예제 입력 2

2 4 3
2 3
1 1

예제 출력 2

-1

예제 입력 3

3 3 3
2 2
2 1
2 1

예제 출력 3

impossible

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2020 B번

  • 문제를 만든 사람: Gregor Schwarz