#abc251c. C - Poem Online Judge

C - Poem Online Judge

Score : 300300 points

问题描述

Poem Online Judge (POJ) 是一个在线评测系统,会为提交的字符串打分。 共有 NN 个提交给 POJ 的作品。在第 ii 个最早提交的作品中,提交了字符串 SiS_i,并获得了分数 TiT_i。(相同的字符串可能被多次提交。) 请注意,POJ 不一定对具有相同字符串的提交给出相同的分数

如果提交中的字符串从未在任何更早的提交中出现过,则称该提交是 原创 提交。 若一个提交是原创提交,并且得分最高,则称其为 最佳 提交。如果有多个这样的提交,仅考虑最早的那一个为最佳提交。

请找出最佳提交的索引。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Poem Online Judge (POJ) is an online judge that gives scores to submitted strings.
There were NN submissions to POJ. In the ii-th earliest submission, string SiS_i was submitted, and a score of TiT_i 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

  • 1N1051 \leq N \leq 10^5
  • SiS_i is a string consisting of lowercase English characters.
  • SiS_i has a length between 11 and 1010, inclusive.
  • 0Ti1090 \leq T_i \leq 10^9
  • NN and TiT_i are integers.

Input

Input is given from Standard Input in the following format:

NN

S1S_1 T1T_1

S2S_2 T2T_2

\vdots

SNS_N TNT_N

Output

Print the answer.

Sample Input 1

3
aaa 10
bbb 20
aaa 30

Sample Output 1

2

We will refer to the ii-th earliest submission as Submission ii.
Original submissions are Submissions 11 and 22. Submission 33 is not original because it has the same string as that in Submission 11.
Among the original submissions, Submission 22 has the highest score. Therefore, this is the best submission.

Sample Input 2

5
aaa 9
bbb 10
ccc 10
ddd 10
bbb 11

Sample Output 2

2

Original submissions are Submissions 11, 22, 33, and 44.
Among them, Submissions 22, 33, and 44 have the highest scores. In this case, the earliest submission among them, Submission 22, 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.

Sample Input 3

10
bb 3
ba 1
aa 4
bb 1
ba 5
aa 9
aa 2
ab 6
bb 5
ab 3

Sample Output 3

8

update @ 2024/3/10 10:42:48