#C12235. Sort Students by Grades

    ID: 41640 Type: Default 1000ms 256MiB

Sort Students by Grades

Sort Students by Grades

You are given a list of student names along with their corresponding grades. Your task is to sort these students primarily by their grades in descending order and, if two or more students have the same grade, by their names in lexicographical (i.e., alphabetical) order in ascending order.

The sorting criteria can be mathematically expressed as sorting by the key ( (-grade, name) ).

For example, given the input below:

5
Alice 90
Bob 85
Charlie 90
David 85
Eve 70

The correct output is:
Alice 90
Charlie 90
Bob 85
David 85
Eve 70

inputFormat

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

- The first line contains an integer ( n ) representing the number of students.
- The next ( n ) lines each contain a student's name and their grade, separated by a space.

outputFormat

Print the sorted list of students to standard output (stdout). Each line should contain the student's name and grade, separated by a space.## sample

5
Alice 90
Bob 85
Charlie 90
David 85
Eve 70
Alice 90

Charlie 90 Bob 85 David 85 Eve 70

</p>