#K59287. Sorting Teams by Points
Sorting Teams by Points
Sorting Teams by Points
You are given a list of teams along with their scores. The task is to sort the teams in descending order of their points. In case of ties (i.e. teams with equal points), the team that appears earlier in the input should come first. Formally, if we have teams with points \(P_1, P_2, \dots, P_n\), then the sorted order should satisfy \(P_i \ge P_j\) for any team \(i\) coming before team \(j\), while preserving the original order among teams with equal points.
The input is read from standard input (stdin) and the output must be printed to standard output (stdout). The first line of the input contains an integer \(n\) which is the number of teams. The following \(n\) lines each contain a team name (a string without spaces) and an integer representing the team's score, separated by a single space.
Your program should output the sorted team names, each on a new line.
inputFormat
The input consists of multiple lines:
- The first line contains a single integer \(n\) (\(1 \le n \le 10^5\)), the number of teams.
- The next \(n\) lines each contain a team name (a string without spaces) and an integer points (\(0 \le points \le 10^9\)) separated by a space.
Input is read from stdin.
outputFormat
Print the team names in the sorted order (descending by points and in original order in case of ties), one team name per line. Output to stdout.
## sample5
Alpha 370
Bravo 415
Charlie 520
Delta 415
Echo 520
Charlie
Echo
Bravo
Delta
Alpha
</p>