#C5377. Selective Team Formation
Selective Team Formation
Selective Team Formation
You are given a list of players. Each player is described by three pieces of information: a name (a string), a skill level (an integer), and a playing position (a string). The allowed positions are goalkeeper, defender, midfielder, and forward.
The task is to select exactly 11 players to form a team that meets the following positional requirements:
- 1 goalkeeper
- 4 defenders
- 4 midfielders
- 2 forwards
From each position, select the players with the highest skill levels. If there are not enough players in any one position to fulfill the requirement, output impossible
.
Note: In the case of a valid team, print the selected players' names in the order in which they are chosen (i.e., first the chosen goalkeeper, then the four defenders in order of descending skill, followed by the four midfielders in order of descending skill, and finally the two forwards in order of descending skill). Each name should be printed on a separate line.
The mathematical formulation for the requirements can be expressed in LaTeX as:
\( \text{Let } G, D, M, F \text{ denote the number of goalkeepers, defenders, midfielders, and forwards respectively. Then:} \)
- \( G \ge 1 \)
- \( D \ge 4 \)
- \( M \ge 4 \)
- \( F \ge 2 \)
inputFormat
The input is read from standard input (stdin) and has the following format:
- An integer
n
representing the total number of players. n
lines follow, each containing a player's information in the format:name skill position
. Thename
andposition
are strings (without spaces), andskill
is an integer.
outputFormat
If a valid team can be formed, print the names of the selected players to standard output (stdout), one per line in the following order:
- The best goalkeeper
- The top 4 defenders (in descending order of skill)
- The top 4 midfielders (in descending order of skill)
- The top 2 forwards (in descending order of skill)
If a valid team cannot be formed, print a single line with the word impossible
.
11
Alice 85 goalkeeper
Bob 90 defender
Charlie 95 defender
David 85 defender
Eve 80 defender
Frank 70 midfielder
Grace 75 midfielder
Heidi 85 midfielder
Ivan 90 midfielder
Judy 60 forward
Mallory 95 forward
Alice
Bob
Charlie
David
Eve
Frank
Grace
Heidi
Ivan
Judy
Mallory
</p>