Problem G
OvalWatch
It’s the year 2020 and OvalWatch is the most popular massive online first person shooter game.
OvalWatch features a set of
In order to keep each match interesting, for every match,
OvalWatch requires that all players select unique characters
and that all characters are selected (there are
This requirement however is problematic because sometimes
multiple players might want to play the same character. For
example, suppose player
Player
BeeLizard, the developer of OvalWatch, wants to eliminate the frustrating player experience of having to pick a character many times just to find one that’s available, and came up with an ingenious algorithm to do so.
Announcing BeeLizard’s OvalWatch’s newest feature: Ghost Leg.
In Ghost Leg, the players are are enumerated horizontally across the top of the page, while the in game characters are enumerated horizontally across the bottom of the page. Vertical lines are drawn connecting each person with the character directly below.
Next, “legs” are added to the page. Each leg is a horizontal line connecting two adjacent vertical lines, and must not touch any other leg.
Finally, each player
As BeeLizard’s intern, you have to implement the GhostLeg feature of OvalWatch.
Input
The first line of the input contains
The next
Output
A single line containing
Sample Input 1 | Sample Output 1 |
---|---|
3 4 0 1 1 3 0 5 1 10 |
1 2 0 |
Sample Input 2 | Sample Output 2 |
---|---|
4 1 1 2 |
0 2 1 3 |