The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to m) at the end of the game, than wins the one of them who scored at least m points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input
The first line contains an integer number n (1 ≤ n ≤ 1000), n is the number of rounds played. Then follow n lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output
Print the name of the winner.
Examples
Input
3 mike 3 andrew 5 mike 2
Output
andrew Input
3 andrew 3 andrew 2 mike 5
Output
andrew
题目大意是有n个输入,每个输入包含一个人名和一个成绩,让你输出总成绩最大的那个人的名字,如果多个人的最后成绩一致,就输出最早达到最大成绩的人
思路:这里就是先全部加起来,找到能达到的最大成绩,然后再加一遍,当有人达到最大成绩时结束(注意:这里的成绩可正可负,所以可能出现中间大于等于最大成绩了,到最后反而比最大成绩小)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
const int maxn=1e5+5;
typedef long long ll;
using namespace std;
map<string,int> p1,p2;
int num[1005];
string str[1005];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>str[i]>>num[i];
p1[str[i]]+=num[i];
}
int max=-1;
for(int i=0;i<n;i++){
if(p1[str[i]]>max)
max=p1[str[i]];
}
for(int i=0;i<n;i++){
p2[str[i]]+=num[i];
if(p2[str[i]]>=max&&p1[str[i]]>=max){//注意这个的数据可正可负,有可能到最后反而不比max大
cout<<str[i]<<endl;
break;
}
}
return 0;
}