|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|2 초||512 MB||5||4||4||80.000%|
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:
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.
4 4 4 3 1 1 1 1 3 2 2
2 4 3 2 3 1 1
3 3 3 2 2 2 1 2 1