Leaderboard Standings

3.4

15 votes
Algorithms, Easy, Hash Maps, Sorting
Problem

There were N submissions made in a programming contest containing infinite problems. Each submission earned the contestant 100 points as none of the submissions is a wrong or a partial submission. You are given the details of the submissions - the username of the contestant and the time taken to solve the problem. Your task is to print the rank list according to the following rules:

  1. The contestant with a higher score gets a higher rank.
  2. If the scores are tied, then the contestant with the least sum of the time taken to solve the problems gets a higher rank.
  3. In case of a tie in both scores and sum of the time taken, they are ranked lexicographically according to their usernames. 

Note: The details of the submissions are not sorted in any order (neither by time nor by username)


INPUT FORMAT

The first line of every test file contains an integer N, the number of submissions. N lines follow, each being the details of ith submission. 

Each of the N lines contains a string Ci, the username of the contestant corresponding to ith submission, and an integer Ti, the time of submission in minutes, separated by a space.


OUTPUT FORMAT

Output the rank of the contestant and the username, in the increasing order of the ranks. Each rank should be displayed in a newline.


CONSTRAINTS

1N106

1len(Ci)10 where len(s) denotes the length of the string s

1Ti120

Number of unique usernames are at most 105

Sample Input
9
Tom 6
Jim 7
Tom 19
Phil 8
Rick 12
Jim 22
Rick 18
Phil 22
Tom 36
Sample Output
1 Tom
2 Jim
3 Phil
4 Rick
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

Tom stands 1st with 300 points since no other contestant scored 300. Jim stands 2nd as he has solved the problems in 29 minutes. Phil and Rick have scored 200 and solved the problems in 30 minutes. According to the third rule, Phil ranks 3rd.

Contributers:
Editor Image

?