atcoder#ABC260D. [ABC260D] Draw Your Cards
[ABC260D] Draw Your Cards
Score : points
Problem Statement
There is a deck consisting of face-down cards with an integer from through written on them. The integer on the -th card from the top is .
Using this deck, you will perform moves, each consisting of the following steps:
- Draw the topmost card from the deck. Let be the integer written on it.
- Stack the drawn card, face up, onto the card with the smallest integer among the face-up topmost cards on the table with an integer greater than or equal to written on them. If there is no such card on the table, put the drawn card on the table, face up, without stacking it onto any card.
- Then, if there is a pile consisting of face-up cards on the table, eat all those cards. The eaten cards all disappear from the table.
For each card, find which of the moves eats it. If the card is not eaten until the end, report that fact.
Constraints
- All values in input are integers.
- is a permutation of (i.e. a sequence obtained by rearranging ).
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line () should describe the card with the integer written on it. Specifically,
- if the card with written on it is eaten in the -th move, print ;
- if that card is not eaten in any move, print .
5 2
3 5 2 1 4
4
3
3
-1
4
In this input, and .
- In the -st move, the card with written on it is put on the table, face up, without stacked onto any card.
- In the -nd move, the card with written on it is put on the table, face up, without stacked onto any card.
- In the -rd move, the card with written on it is stacked, face up, onto the card with written on it.- Now there is a pile consisting of face-up cards, on which and from the top are written, so these cards are eaten.
- In the -th move, the card with written on it is stacked, face up, onto the card with written on it.- Now there is a pile consisting of face-up cards, on which and from the top are written, so these cards are eaten.
- In the -th move, the card with written on it is put on the table, face up, without stacked onto any card.
- The card with written on it was not eaten until the end.
5 1
1 2 3 4 5
1
2
3
4
5
If , every card is eaten immediately after put on the table within a single move.
15 3
3 14 15 9 2 6 5 13 1 7 10 11 8 12 4
9
9
9
15
15
6
-1
-1
6
-1
-1
-1
-1
6
15