Basketball
InterviewTime limit1sMemory limit1024 MB
Simulate m substitutions between the odd-position and even-position teams, then list the players on the court in alphabetical order.
- Level
Easy3 of 10
- Topics
- Simulation, Sorting
- Solved
- No attempts yet
Problem
During physical education, the students of class 10-A play basketball. The class has students who stand in a row. The PE teacher splits them into two teams as follows: the first team gets the students standing in odd positions (first, third, fifth, and so on). The students in even positions (second, fourth, sixth, and so on) form the second team.
Each team always has students on the court. At the start, the students standing earliest in the original line from each team go on the court. So that every student gets to play, the teacher makes substitutions in both teams every minute.
The player who has spent the most minutes on the court so far (not necessarily consecutively) goes to the bench. If several players are tied, the one with the largest number in the original line goes to rest.
The bench player who has spent the fewest minutes on the court so far comes onto the court. If several are tied, the one with the smallest number in the original line comes in.
The teacher wants to know who will be on the court after substitutions. Help him find out.
For example, suppose six students stand in this order: Ivanov, Petrov, Sidorov, Andreev, Kazakov, Sergeev. The teams are formed as follows. First team: Ivanov, Sidorov, Kazakov. Second team: Petrov, Andreev, Sergeev. Suppose 2 players are on the court at once. Then at the start Ivanov and Sidorov from the first team and Petrov and Andreev from the second team take the court.
After the first minute, Sidorov and Andreev go to the bench, and Kazakov and Sergeev come on. After the second minute, Ivanov and Petrov rest, and Sidorov and Andreev return. After the third minute, Kazakov and Sergeev rest again, and Sidorov and Andreev come on. So after three substitutions the court has (in alphabetical order) Andreev, Ivanov, Petrov, and Sidorov.
Input
The first line contains three integers , , and (, , ). The next lines each contain one surname, the players in the order they originally stood in the line. Each surname is a non-empty string of Latin letters, at most 50 characters long. All surnames are distinct.
Output
Print the surnames of the players who are on the court after substitutions, in alphabetical order. Separate the surnames with spaces.