#C7775. Leaderboard Generation

    ID: 51683 Type: Default 1000ms 256MiB

Leaderboard Generation

Leaderboard Generation

You are given a list of participants along with their scores. Your task is to generate a sorted leaderboard. The sorting criteria are as follows:

  • The participants are sorted primarily by their scores in descending order.
  • If two or more participants have the same score, they should be sorted alphabetically by their names in ascending order.

The input is provided through stdin. The first line contains an integer n which represents the number of participants. The next n lines each contain a participant's name followed by their score. Your program should print the sorted leaderboard to stdout, with each line displaying the participant's name and score separated by a space.

Note: If there are no participants (i.e., n is 0), no output should be produced.

inputFormat

The first line of input contains an integer n (n ≥ 0) — the number of participants. Each of the following n lines contains a string and an integer separated by a space representing a participant's name and their score respectively.

For example:

4
Alice 50
Bob 75
Charlie 75
David 60

outputFormat

Output the sorted leaderboard to stdout. Each line should contain a participant's name and their score separated by a space. The leaderboard must be sorted first by descending score and then by ascending lexicographical order of names for those with equal scores.

For the sample input above, the expected output is:

Bob 75
Charlie 75
David 60
Alice 50
## sample
4
Alice 50
Bob 75
Charlie 75
David 60
Bob 75

Charlie 75 David 60 Alice 50

</p>