Codeforces Beta Round #2
来源:互联网 发布:风电中国 知乎 编辑:程序博客网 时间:2024/05/21 17:01
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.
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.
Print the name of the winner.
3
mike 3
andrew 5
mike 2
andrew
3
andrew 3
andrew 2
mike 5
andrew
/* ***********************************************
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;
}
- Codeforces Beta Round #2
- Codeforces Beta Round #2
- Codeforces Beta Round #2
- Codeforces Beta Round #2
- Codeforces Beta Round #2
- Codeforces Beta Round #2 B
- Codeforces Beta Round #2 练习
- Codeforces Beta Round #63 (Div. 2)
- Codeforces Beta Round #65 (Div. 2)
- Codeforces Beta Round #67 (Div. 2) ABCD
- Codeforces Beta Round #80 (Div. 2 Only)
- Codeforces Beta Round #83 (Div. 2 Only)
- Codeforces Beta Round #86 (Div. 2 Only)
- Codeforces Beta Round #85 div 2
- Codeforces Beta Round #93 (Div. 2 Only)
- Codeforces Beta Round #95 (Div. 2)
- Codeforces Beta Round #96 (Div. 2)
- Codeforces Beta Round #96 (Div. 2)
- (转)图算法单源最短路径Dijkstra算法(邻接表/邻接矩阵+优先队列STL)
- Codeforces Round #303 (Div. 2)
- BestCoder Round #42(3/4)
- Vijos之暴力枚举
- Codeforces Beta Round #1
- Codeforces Beta Round #2
- Codeforces Beta Round #3
- 广义表的基本操作实现
- Codeforces Beta Round #4 (Div. 2 Only)
- Codeforces Beta Round #5
- Providing Resource
- leetcode——338——Counting Bits
- HDU 1878 欧拉回路
- Codeforces Beta Round #6 (Div. 2 Only)