A group of N high school students wants to play a basketball game. To divide themselves into two teams they first rank all the players in the following way:
- Players with a higher shot percentage are rated higher than players with a lower shot percentage.
- If two players have the same shot percentage, the taller player is rated higher.
Luckily there are no two players with both the same shot percentage and height so they are able to order themselves in an unambiguous way. Based on that ordering each player is assigned a draft number from the range [1..N], where the highest-rated player gets the number 1, the second highest-rated gets the number 2, and so on. Now the first team contains all the players with the odd draft numbers and the second team all the players with the even draft numbers.
Each team can only have P players playing at a time, so to ensure that everyone gets similar time on the court both teams will rotate their players according to the following algorithm:
- Each team starts the game with the P players who have the lowest draft numbers.
- If there are more than P players on a team after each minute of the game the player with the highest total time played leaves the playing field. Ties are broken by the player with the higher draft number leaving first.
- To replace her the player on the bench with the lowest total time played joins the game. Ties are broken by the player with the lower draft number entering first.
The game has been going on for M minutes now. Your task is to print out the names of all the players currently on the field, (that is after M rotations).
The first line of the input consists of a single number T, the number of test cases.
Each test case starts with a line containing three space separated integers N M P
The subsequent N lines are in the format "<name> <shot_percentage> <height>". See the example for clarification.
1 ≤ T ≤ 50
2 * P ≤ N ≤ 30
1 ≤ M ≤ 120
1 ≤ P ≤ 5
Each name starts with an uppercase English letter, followed by 0 to 20 lowercase English letters. There can be players sharing the same name. Each shot percentage is an integer from the range [0..100]. Each height is an integer from the range [100..240]
For each test case i numbered from 1 to T, output "Case #i: ", followed by 2 * P space separated names of the players playing after M rotations. The names should be printed in lexicographical order.
In the first example if you sort all the players by their shot percentage you get the list: [Wai, Purav, Weiyan, Slawek, Lin, Meihong]. This makes the two teams:
[Wai, Weiyan, Lin]
[Purav, Slawek, Meihong]
The game starts with Lin and Meihong sitting on the bench in their respective teams. After the first minute passes it's time for Weiyan and Slawek to sit out since they have the highest draft numbers of the people who played. After the second minute passes Lin and Meihong will keep playing since they only played one minute so far and it's Wai and Purav who have to sit out.
Finally after the third minute Lin and Maihong go back to the bench
and all the players currently playing again are:
Purav Slawek Wai Weiyan
5
6 3 2
Wai 99 131
Weiyan 81 155
Lin 80 100
Purav 86 198
Slawek 80 192
Meihong 44 109
7 93 2
Paul 82 189
Kittipat 62 126
Thomas 17 228
Fabien 57 233
Yifei 65 138
Liang 92 100
Victor 53 124
6 62 3
Meihong 33 192
Duc 62 162
Wai 70 148
Fabien 19 120
Bhuwan 48 176
Vlad 30 225
8 59 3
Anil 38 180
Song 7 187
David 65 159
Lin 45 121
Ranjeeth 39 183
Torbjorn 26 181
Clifton 57 158
Phil 3 183
4 72 1
Anh 2 187
Erling 69 226
Purav 0 199
Zejia 29 163
Case #1: Purav Slawek Wai Weiyan
Case #2: Fabien Kittipat Liang Paul
Case #3: Bhuwan Duc Fabien Meihong Vlad Wai
Case #4: Anil Lin Phil Ranjeeth Song Torbjorn
Case #5: Erling Zejia
Problem number 1 of the Facebook Hacker Cup 2014 Qualification Round
This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
https://www.facebook.com/hackercup/problems.php?pid=740733162607577&round=598486203541358