Portal

Portal1: Codeforces

Portal2: Luogu

Description

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 "\(\texttt{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 \le n \le 1000)\), \(n\) is the number of rounds played. Then follow \(n\) lines, containing the information about the rounds in "\(\texttt{name score}\)" format in chronological order, where \(\texttt{name}\) is a string of lower-case Latin letters with the length from \(1\) to \(32\), and \(\texttt{score}\) is an integer number between \(-1000\) and \(1000\), inclusive.

Output

Print the name of the winner.

Sample Input1

3
mike 3
andrew 5
mike 2

Sample Output1

andrew

Sample Input2

3
andrew 3
andrew 2
mike 5

Sample Output2

andrew

Description in Chinese

Berland流行着纸牌游戏“Berlogging”,这个游戏的赢家是根据以下规则确定的:在每一轮中,玩家获得或失去一定数量的分数,在游戏过程中,分数被记录在“名称和得分”行中,其中名字是玩家的名字,得分是在这一轮中获得的分数。得分是负值意味着玩家失去了相应的分数。如果在比赛结束时只有一名玩家分数最多,他就是获胜者。如果两名或两名以上的玩家在比赛结束时都有最大的分数\(m\),那么其中首先获得至少\(m\)分的玩家胜利。开始时,每个玩家都是\(0\)分。保证在比赛结束时至少有一个玩家的分数为正。

Solution

把每个人的得分存到\(\texttt{map}\)里,然后求出最大得分,再寻找最先到达最大得分的人,即为获胜者。

Code

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map> using namespace std; const int INF = 0x3f3f3f3f, MAXN = 1005;
int n, a[MAXN];
string name[MAXN];
map<string, int> Map1, Map2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> name[i] >> a[i];
Map1[name[i]] += a[i];
}//映射到map里
int Max = -INF;
for (int i = 0; i < n; i++)
if (Map1[name[i]] > Max) Max = Map1[name[i]];//求出最大得分
for (int i = 0; i < n; i++) {
Map2[name[i]] += a[i];
if (Map2[name[i]] >= Max && Map1[name[i]] >= Max) {
cout << name[i] << endl;//输出最先到最大得分的人
return 0;
}
}
return 0;
}

『题解』Codeforces2A Winner的更多相关文章

  1. 『题解』洛谷P1063 能量项链

    原文地址 Problem Portal Portal1:Luogu Portal2:LibreOJ Portal3:Vijos Description 在\(Mars\)星球上,每个\(Mars\)人 ...

  2. 『题解』Codeforces1142A The Beatles

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently a Golden Circle of Beetlovers ...

  3. 『题解』Codeforces1142B Lynyrd Skynyrd

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Recently Lynyrd and Skynyrd went to a ...

  4. 『题解』洛谷P1993 小K的农场

    更好的阅读体验 Portal Portal1: Luogu Description 小\(K\)在\(\mathrm MC\)里面建立很多很多的农场,总共\(n\)个,以至于他自己都忘记了每个农场中种 ...

  5. 『题解』洛谷P2296 寻找道路

    更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 在有向图\(\mathrm G\)中,每条边的长度均为\(1\),现给定起点和终点 ...

  6. 『题解』洛谷P1351 联合权值

    更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Description 无向连通图\(\mathrm G\)有\(n\)个点,\(n - 1\)条边.点从 ...

  7. 『题解』Codeforces656E Out of Controls

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description You are given a complete undirected gr ...

  8. 『题解』洛谷P2170 选学霸

    更好的阅读体验 Portal Portal1: Luogu Description 老师想从\(N\)名学生中选\(M\)人当学霸,但有\(K\)对人实力相当,如果实力相当的人中,一部分被选上,另一部 ...

  9. 『题解』洛谷P1083 借教室

    更好的阅读体验 Portal Portal1: Luogu Portal2: LibreOJ Portal3: Vijos Description 在大学期间,经常需要租借教室.大到院系举办活动,小到 ...

随机推荐

  1. Node.js入门教程 第五篇 (Express框架)

    Express框架 Express是适用于Node.js web的框架,提供了大量实用功能,例如路由功能及http功能. Express 框架核心特性: 可以设置中间件来响应 HTTP 请求. 定义了 ...

  2. A-05 前向选择法和前向梯度法

    目录 前向选择法和前向梯度法 一.前向选择法 1.1 余弦相似度求投影 1.2 举例 1.3 前向选择法优缺点 1.3.1 优点 1.3.2 缺点 二.前向梯度法 2.1 举例 2.2 前向梯度法优缺 ...

  3. html5视频常用API接口

    一.虽然有的属性是boolean类型,但仍旧建议按照XHTML书写(属性名=”属性值”)格式,避免出现错误 (下面加粗的属性为常用属性) 属性 值 功能描述 controls controls 是否显 ...

  4. 玩转ADB命令(ADB命令使用大全)转载

    ADB是什么 Adb的全称为Android Debug Bridge:android调试桥梁,下图为Android官方对adb的介绍:可以看出,Android的初衷是用adb这样的一个工具来协助开发人 ...

  5. 因果推理的春天-实用HTE(Heterogeneous Treatment Effects)论文github收藏

    一直以来机器学习希望解决的一个问题就是'what if',也就是决策指导: 如果我给用户发优惠券用户会留下来么? 如果患者服了这个药血压会降低么? 如果APP增加这个功能会增加用户的使用时长么? 如果 ...

  6. vc++中字符串的免杀

    一:格式字符: http://baike.baidu.com/view/2194593.htm d:以十进制形式输出带符号整数(正数不输出符号)o:以八进制形式输出无符号整数(不输出前缀o)x:以十六 ...

  7. Python开发【第十一篇】函数

    函数 什么是函数? 函数是可以重复执行的语句块,可以重复调用并执行函数的面向过程编程的最小单位. 函数的作用: 函数用于封装语句块,提高代码的重用性,定义用户级别的函数.提高代码的可读性和易维护性. ...

  8. Spring Boot2 系列教程(十五)定义系统启动任务的两种方式

    在 Servlet/Jsp 项目中,如果涉及到系统任务,例如在项目启动阶段要做一些数据初始化操作,这些操作有一个共同的特点,只在项目启动时进行,以后都不再执行,这里,容易想到web基础中的三大组件( ...

  9. c++::Mysql::ORM 开发环境搭建

    官网地址:https://www.codesynthesis.com/products/odb/ 环境搭建:ubuntu16.04-64 1.安装mysqlClient sudo apt-get in ...

  10. java中常见的字符串API

    java中定义了String类来封装字符串,并提供一系列的操作字符串的方法,他们都位于java.lang包下. package Main; public class String01 { public ...