ShaShka (ШАШКА)
Time limit2sMemory limit1024 MB
Update Elo ratings after each game in input order, then print all players by rating descending and surname ascending.
- Level
Easy3 of 10
- Topics
- Simulation, Hash map, Sorting
- Solved
- No attempts yet
Statement
Petr is in charge of rating calculations for the Chess Association of Chess Players of the Antarctic Conglomerate (ШАШКА). The association uses Elo ratings, and a rating is a non-negative integer. After each game, ratings are recalculated with the following rules:
Here and are the ratings of players A and B before the game, is the score A earned in the game (0 for a loss, 0.5 for a draw, 1 for a win), and is the new rating of A. The new rating is rounded down to the nearest integer. If it becomes negative, it is set to zero.
Input
The first line contains one integer (). Each of the next lines contains a non-negative integer (), the rating of the -th player before the tournament, and the player's surname, separated by one space. A surname consists of uppercase and lowercase Latin letters and is at most 50 characters long. Surnames are non-empty and all different.
The next line contains the number of games (). Each of the next lines contains the surnames of the first and second players, followed by an integer : means the first player won, means the second player won, and means a draw. Games are listed in the order they were played.
Output
Print the players in decreasing order of rating. If two ratings are equal, the player whose surname is lexicographically smaller comes first. Use the same format as the input: each line contains the rating and the surname separated by one space.