#C11358. Student Score Sorting

    ID: 40665 Type: Default 1000ms 256MiB

Student Score Sorting

Student Score Sorting

You are given a list of students with their corresponding scores. Your task is to sort the students primarily by their scores in descending order, and if two or more students have the same score, sort them in ascending lexicographical order by their names.

Formally, if you are given an integer \( n \) representing the number of students and \( n \) lines each containing a student's name and score, you need to output the list of student names after sorting using the following criteria:

  • Sort by score in descending order (i.e., larger scores come first).
  • If scores are equal, sort by name in ascending order (i.e., lexicographically smallest first).

Note: The sorting conditions can be expressed mathematically as: For two students \( a \) and \( b \) with scores \( s_a \) and \( s_b \) and names \( n_a \) and \( n_b \), student \( a \) should come before \( b \) if either \( s_a > s_b \) or \( s_a = s_b \) and \( n_a < n_b \) (in lexicographical order).

inputFormat

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

n
name1 score1
name2 score2
... 
name_n score_n

Here, \( n \) is an integer representing the number of students, and for each student, a line is provided containing the student's name (a string without spaces) and score (an integer), separated by a space.

outputFormat

Output the sorted list of student names to standard output (stdout), with each name on a separate line.

## sample
4
Alice 85
Bob 90
Charlie 85
David 92
David

Bob Alice Charlie

</p>