#K33847. Sort Students by Grade and Name

    ID: 25178 Type: Default 1000ms 256MiB

Sort Students by Grade and Name

Sort Students by Grade and Name

You are given a list of students, each identified by a name and a grade. Your task is to sort the students in descending order of their grades. In case multiple students have the same grade, they should be sorted in ascending alphabetical order of their names.

The input is provided via standard input (stdin) and the result should be output to standard output (stdout). The output should display each student on a separate line with their name followed by their grade, separated by a space.

The sorting criteria can be mathematically described as follows:

For two students, i and j, with grades \(g_i\) and \(g_j\) and names \(n_i\) and \(n_j\) respectively, student i should come before student j if either:

  • \(g_i > g_j\), or
  • \(g_i = g_j\) and \(n_i < n_j\) (in lexicographical order).

inputFormat

The first line of input contains an integer \(n\) representing the number of students. Each of the following \(n\) lines contains a student's name and grade separated by a space.

Constraints:

  • \(0 \leq n \leq 10^5\)
  • Name is a non-empty string without spaces and grade is an integer.

outputFormat

Output \(n\) lines, each containing a student's name and grade separated by a space, reflecting the sorted order.

## sample
4
Jake 90
Amy 85
Terry 90
Rosa 100
Rosa 100

Jake 90 Terry 90 Amy 85

</p>