Card Counting Club
Time limit8sMemory limit1024 MB
Given N hands of cards and a penalty P per mark, print the order in which players run out of cards in the counting-out game.
- Level
Medium6 of 10
- Topics
- Heap, Simulation, Greedy
- Solved
- No attempts yet
Problem
The Card Counting Club wanted to combine its card counting practice with choosing the player order for its games. They settled on a counting-out game played as follows.
- At the start, each player is dealt a hand with the same number of cards as everyone else.
- Each turn, every player shows the card with the smallest value in their hand to the other players.
- The player with the smallest card discards it.
- Only one player discards their card. Ties are broken by choosing the player whose name comes first in standard dictionary (lexicographic) order.
- Every player who does not discard leaves a small mark on their card and returns it to their hand. Each mark increases the card's value by the agreed penalty amount P.
- A player who runs out of cards is counted out.
- The game continues until all players are counted out.
The order in which the players are counted out sets the order in which club members play other games.
Input
The first line contains three integers , , and (, , ). is the number of players, is the hand size of each player, and is the penalty added for each mark.
The next lines each contain a player's name, followed by space-separated integers () that are the card values in that player's hand. Values may repeat within a hand and across hands. Each name consists only of uppercase letters and has a length between 2 and 10.
Output
On a single line, print the player names in the order in which they are counted out during the game. Separate consecutive names with a single space.