#C6597. Sort Student Records

    ID: 50374 Type: Default 1000ms 256MiB

Sort Student Records

Sort Student Records

Given a list of student records where each record consists of a student's name and their grade, your task is to sort the records based on the following criteria:

  • Sort by grade in descending order.
  • If two or more students have the same grade, sort them by their name in lexicographical (alphabetical) order.

The sorting should satisfy the condition \[ \text{If } a, b \text{ are records, then } a \text{ is before } b \text{ if and only if}\] \[ (a.grade > b.grade) \text{ or } (a.grade = b.grade \text{ and } a.name < b.name). \]

inputFormat

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

  1. The first line contains a single integer \(N\) (\(1 \leq N \leq 10^5\)) representing the number of student records.
  2. Each of the next \(N\) lines contains a student's name (a string without spaces) and an integer grade, separated by a space.

outputFormat

Output the sorted student records to stdout with each record on a new line. Each line should contain the student's name and grade separated by a space, following the sorted order described above.

## sample
3
Alice 85
Bob 90
Charlie 85
Bob 90

Alice 85 Charlie 85

</p>