PivotOJ

Bohemian Bookshelf

시간 제한: 4000ms메모리 제한: 2048MB출처: NCPC 2025BOJ 35217

문제

When it comes to shelving books, bibliophiles and interior decorators rarely agree: vertical or horizontal---what’s the right way? Ever skeptical of orthodoxy, you embrace both! Your bookshelf displays a composed mix: upright volumes standing with quiet discipline next to a single, neatly arranged stack, like a literary ziggurat. The effect signals bohemian chic with a touch of endearing academic absent-mindedness and just enough polish to suggest you’ve definitely read some of the books.

A book is characterised by its spine height and thickness. It can fit upright if its height does not exceed the bookshelf's height. Alternatively, books can form a stack by being laid flat on their sides on top of each other; for aesthetic reasons the books forming such a stack must be arranged in nonincreasing order of spine height. Their total thickness may not exceed the height of the bookshelf. The total thickness of the upright books and the width of the stack may not exceed the width of the bookshelf.

The books in Sample 11 can be arranged like this:

입력

The input consists of:

  • One line with integers NN, HH, WW (2N1002\leq N\leq 100, 130H350130 \leq H\leq 350, 300W900300\leq W\leq 900), the number of books you want to display, the height of the bookshelf in millimeters, and the width of the bookshelf in millimeters,
  • NN lines, one for each book, with two integers hh, tt (76h48376\leq h\leq 483, 5t605\leq t\leq 60), the book's spine height and thickness in millimeters. On its own, every book fits on the shelf either standing up or on its side, so we also have hmax(W,H)h\leq \max(W, H).

출력

Output two lines.

The first line starts with the word "upright", followed by the indices of the upright books. The second line starts with the word "stacked", followed by the indices of the books in the stack, in order from bottom to top. There must be at least one upright book and at least one stacked book. Books are indexed 11, \ldots, NN.

If there is more than one solution, you may output any one of them. If no such arrangement is possible, print "impossible".

예제

예제 1

입력
3 250 350
178 32
200 60
297 50
출력
upright 1
stacked 3 2

예제 2

입력
2 300 300
290 60
290 60
출력
impossible
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.