atcoder#ABC251C. [ABC251C] Poem Online Judge
[ABC251C] Poem Online Judge
Score : points
Problem Statement
Poem Online Judge (POJ) is an online judge that gives scores to submitted strings. There were submissions to POJ. In the -th earliest submission, string was submitted, and a score of was given. (The same string may have been submitted multiple times.) Note that POJ may not necessarily give the same score to submissions with the same string.
A submission is said to be an original submission if the string in the submission is never submitted in any earlier submission. A submission is said to be the best submission if it is an original submission with the highest score. If there are multiple such submissions, only the earliest one is considered the best submission.
Find the index of the best submission.
Constraints
- is a string consisting of lowercase English characters.
- has a length between and , inclusive.
- and are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
aaa 10
bbb 20
aaa 30
2
We will refer to the -th earliest submission as Submission . Original submissions are Submissions and . Submission is not original because it has the same string as that in Submission . Among the original submissions, Submission has the highest score. Therefore, this is the best submission.
5
aaa 9
bbb 10
ccc 10
ddd 10
bbb 11
2
Original submissions are Submissions , , , and . Among them, Submissions , , and have the highest scores. In this case, the earliest submission among them, Submission , is the best. As in this sample, beware that if multiple original submissions have the highest scores, only the one with the earliest among them is considered the best submission.
10
bb 3
ba 1
aa 4
bb 1
ba 5
aa 9
aa 2
ab 6
bb 5
ab 3
8