
/*
* Winner.cpp
*
* Created on: 2013-10-13
* Author: wangzhu
*/ /**
* 先找出所有选手的分数和中最大的分数和,之后在所有选手的分数和中看有几个是和最大的分数和相等,
* 1)、若有多个,则比较谁在比赛结束钱分数先达到最大分数和,则是赢家;
* 2)、若只有一个,则直接输出。
*/
#include<cstdio>
#include<iostream>
#include<map>
#include<string.h>
using namespace std;
#define NMAX 1010
struct Node {
int index, val;
char name[];
};
Node node[NMAX];
map<string, int> myMap;
map<string, int> myMap1;
map<string, int>::iterator mapIterator; void find(int n, int nmax) {
int m;
for (int i = ; i < n; i++) {
for (mapIterator = myMap1.begin(); mapIterator != myMap1.end();
mapIterator++) {
if ( == strcmp(node[i].name, mapIterator->first.c_str())) {
// printf("%d %d %s\n", node[i].index, node[i].val, node[i].name);
m = myMap1[mapIterator->first];
m += node[i].val;
myMap1[mapIterator->first] = m;
if (m >= nmax) {
printf("%s\n", node[i].name);
return;
}
}
}
}
} int main() {
freopen("data.in", "r", stdin);
int n, m,nmax;
string nmaxStr;
while (~scanf("%d", &n)) {
myMap.clear();
myMap1.clear(); for (int i = ; i < n; i++) {
scanf("%s%d", node[i].name, &node[i].val);
node[i].index = i;
myMap[node[i].name] +=node[i].val;
}
nmax = -;
for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
if(nmax < mapIterator->second){
nmax = mapIterator->second;
}
}
m = ;
for(mapIterator = myMap.begin();mapIterator!=myMap.end();mapIterator++){
if(nmax == mapIterator->second){
nmaxStr = mapIterator->first;
myMap1[mapIterator->first] = ;
m ++;
}
}
//printf("%d %d\n",m,nmax);
if(m != ){
find(n,nmax);
}else{
printf("%s\n",nmaxStr.c_str());
}
}
return ;
}