P23734 [AtCoder] [ABC033B] Town Merger
入门
题目描述

Problem Description

$ N $ towns are merging to form one new city. The name of the $i\ (1 ≦ i ≦ N)$th town before the merger is $ S_i $, and its population is $ P_i $. The name of the new city is decided as follows:

  • If there is a town with a population greater than half of the total population of all towns, the new city will inherit the name of that town.
  • If no such town exists, the new city will be named atcoder.

Given the names and populations of each town, output the name of the new city after the merger.

Input Format

The input is given from the standard input in the following format:

$ N $ $ S_1 $ $ P_1 $ $ S_2 $ $ P_2 $ : $ S_N $ $ P_N $

  • The first line contains an integer $N\ (2 ≦ N ≦ 1,000)$.
  • The next $ N $ lines contain the information for each town. The $ i $th line contains a string $ S_i $ of length between 1 and 20 consisting of lowercase English letters, and an integer $P_i\ (1 ≦ P_i ≦ 100,000)$, separated by a space.
  • $ S_1 $, $ S_2 $, …, $ S_N $ are all different.

Output Format

Output the name of the new city after the merger on one line.

Ensure a newline at the end of the output.

Sample Input and Output

Sample Input #1

4
unagi 20
usagi 13
snuke 42
smeke 7

Sample Output #1

snuke

Sample Input #2

5
a 10
b 20
c 30
d 40
e 100

Sample Output #2

atcoder

Sample Input #3

14
yasuzuka 3340
uragawara 4032
oshima 2249
maki 2614
kakizaki 11484
ogata 10401
kubiki 9746
yoshikawa 5142
joetsu 100000
nakago 4733
itakura 7517
kiyosato 3152
sanwa 6190
nadachi 3169

Sample Output #3

joetsu

Notes/Hints

Sample Explanation 1

The total population of the 4 towns is $ 20 + 13 + 42 + 7 = 82 $. The 3rd town has more than half of this population.

Sample Explanation 2

The total population of the 5 towns is $ 10 + 20 + 30 + 40 + 100 = 200 $, but no town has more than half of this population, so the city name becomes atcoder. Note that the 5th town has exactly half of the total population, which is not more than half.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 unagi 20 usagi 13 snuke 42 smeke 7
样例输出
snuke