#K13026. Sort Friends by Scores

    ID: 23821 Type: Default 1000ms 256MiB

Sort Friends by Scores

Sort Friends by Scores

You are given a list of friends with their corresponding scores. Your task is to sort the friends' names in descending order based on their scores. In case of a tie (i.e. when two or more friends have the same score), sort their names in ascending alphabetical order.

Note: The sorting criteria can be mathematically expressed as follows:

For two friends with score values \(s_1\) and \(s_2\) and names \(n_1\) and \(n_2\), they are ordered such that either \(s_1 > s_2\) or \(s_1 = s_2\) and \(n_1 < n_2\) (in lexicographical order).

inputFormat

The input is read from stdin and has the following format:

  • The first line contains an integer \(n\): the number of friends.
  • The following \(n\) lines each contain a friend's name (a string) and an integer score, separated by a space.

For example:

5
Alice 50
Bob 75
Charlie 50
David 100
Eve 75

outputFormat

Output the sorted list of friend names to stdout, each on a new line.

For the sample input above, the output should be:

David
Bob
Eve
Alice
Charlie
## sample
5
Alice 50
Bob 75
Charlie 50
David 100
Eve 75
David

Bob Eve Alice Charlie

</p>