Codeforces Beta Round #2

来源:互联网 发布:风电中国 知乎 编辑:程序博客网 时间:2024/05/21 17:01
http://codeforces.com/contest/2/problem/A
A. Winner
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
3
mike 3
andrew 5
mike 2
output
andrew
input
3
andrew 3
andrew 2
mike 5
output
andrew
题目大意就是:n代表轮数,每轮给出人名和他要的到的分数(负分数代表扣的分数),最后在这几轮结束后,看谁的分数最多。如果有多个人的最高分相同,则第一个达到最高分的人为winner
如果最后有多个人分数都是最高的,则这些人里面,在比赛过程中首先达到或者超过这个分数的人夺冠
/* ***********************************************
Author :
Created Time :2015/5/30 21:31:27
File Name :3.cpp
************************************************ */

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;

bool cmp(int a,int b){
return a>b;
}
map
<string,int>mp;
map
<string,int>p;
string ss[1100];
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
mp
.clear();
p
.clear();
string s;int d[maxn];
string ans;
int Max=-INF;
for(int i=1;i<=n;i++){
cin
>>ss[i]>>d[i];
mp
[ss[i]]+=d[i];
}
for(int i=1;i<=n;i++)
Max=max(mp[ss[i]],Max);
for(int i=1;i<=n;i++){
p
[ss[i]]+=d[i];
if(mp[ss[i]]==Max&&p[ss[i]]>=Max){
cout
<<ss[i]<<endl;break;
}
}
}
return 0;
}

0 0