# CF2A Winner(map+思维)

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 mm ) at the end of the game, than wins the one of them who scored at least mm 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 nn ( 1<=n<=10001<=n<=1000 ), nn is the number of rounds played. Then follow nn 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.

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll maxx = 1e18;
const int N = 1e6+100;
const int ps = 1e4+10;
const double eps = 1e-8;
map<string,int >mp,mps;
int n,k,max1;
string s[1001],ans;
int a[1001];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>s[i]>>a[i];
mp[s[i]]+=a[i];
}//第一遍处理，记录最终状态
for(auto k : mp)
{
max1=max(max1,k.second);
}//找出最大分
for(int i=1;i<=n;i++)
{
mps[s[i]]+=a[i];
if(mp[s[i]]==max1&&mps[s[i]]>=max1)
{
ans=s[i];
break;
}
}//第二遍处理，找出分数等于最大分且在过程中第一个 >= 最大分的选手
cout<<ans;
}


|
4月前
|

Set和Map的应用场景
Set和Map的应用场景
31 0
|
12月前
CF1553B Reverse String(数学思维）
CF1553B Reverse String(数学思维）
34 0
|
2月前
|

【C++】map和set深度讲解（下）
【C++】map和set深度讲解（下）
47 2
|
2月前
|

【C++】map和set深度讲解（上）
【C++】map和set深度讲解（上）
31 2
|
3月前
|

24 0
|
4月前
|

c++的学习之路：25、map与set
c++的学习之路：25、map与set
33 0
|
12月前
CF219A k-String（数学分析）
CF219A k-String（数学分析）
59 0
|

CF1660C Get an Even String(贪心)
CF1660C Get an Even String(贪心)
89 0
CF763A Timofey and a tree（思维）
CF763A Timofey and a tree（思维）
71 0