A. Winner

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


思路:

该题求解玩家的最高分获得者,需要说明的一点是:如果有最高分相同的玩家,即最终得分都是最高分,那么其中最先达到或超过最高分(score >= max, 原题说明who scored at least m points first)的玩家获胜。

该题由于可能要求得最先达到最高分的玩家,因此使用两次计算的方法,第一次先求得所有玩家的最终得分,并从中选取最高分;第二次为了找到最先达到最高分的玩家,需要再计算一遍得分过程,当score>=max时,便是最终答案。

坑点:由于会有扣分情况,即出现负数,所以不能直接一次循环比较当前max值得到最高分,因为在扣分后,max可能不再满足是当前选手中的成绩(例如,max是100,刚好该选手现在被扣分,成了90,但是max的值并未被更新为当前所有成绩的最大值)


code:

#include <iostream>
#include <string>
#include <map>
using namespace std;int main() {map< string, int > _map;  //记录所有玩家最终成绩map< string, int > _map2;  //二次计算得最先达到最高分的玩家string name[1000];int score[1000], n, max = -99999999;cin >> n;for( int i = 0; i < n; i++ ) {cin >> name[i] >> score[i];_map[ name[i] ] += score[i];}/* 获得最高分 */map< string, int >::iterator it;for( it = _map.begin(); it != _map.end(); it++ ) {if ( max < it->second ) {max = it->second;}}for( int i = 0; i < n; i++ ) {if ( _map[ name[i] ] == max ) {_map2[ name[i] ] += score[i];/* 最先达到最高分 */if ( _map2[ name[i] ] >= max ) {  cout << name[i];break;}}}return 0;
}

CodeForce 2A —— Winner相关推荐

  1. Codeforces Beta Round #2-A. Winner——算法笔记

    题目链接:http://codeforces.com/problemset/problem/2/A 题目描述: The winner of the card game popular in Berla ...

  2. Winner 赢家 (2A - Winner) map

    The winner of the card game popular in Berland "Berlogging" is determined according to the ...

  3. 2A. Winner

    A. Winner time limit :per test 1 second memory limit: per test 64 megabytes input: standard input ou ...

  4. 【Codeforces】 2A - Winner (map)

    http://codeforces.com/problemset/problem/2/A So, if two or more players have the maximum number of p ...

  5. 【CF#2A】Winner(模拟 STL-map)☆

    题干: The winner of the card game popular in Berland "Berlogging" is determined according to ...

  6. 四百元值不值——论小米2A与2S

    作为一个米2用户,面对这手机市场极快的更新速度,有些跟不上速度.最近出了小米2A与2S,碰巧有人问值不值的问题,于是就小小的进行了一个研究,跟大家讨论一下. 首先小米2A与2S在我看来就是2的翻版,现 ...

  7. 【leetcode】486. Predict the Winner

    题目如下: Given an array of scores that are non-negative integers. Player 1 picks one of the numbers fro ...

  8. A winner is a dreamer who never gives up

    A winner is a dreamer who never gives up. 成功者是坚持梦想不放弃的人.(Nelson Mandela) 转载于:https://www.cnblogs.com ...

  9. winner or loser

    Carol Dweck 非常痴迷于对"失败"的研究.你知道的,有些人好像生来就是 winner,做什么事都很顺利都很成功,而另外一些人则一直很无助,好像这辈子注定是个 loser. ...

最新文章

  1. C#模糊查询绑定datagridview
  2. 系统发生 1219 错误。 提供的凭据与已存在的凭据集冲突。
  3. java 二分查找
  4. for和foreach分析
  5. EXCEL文件上传与下载
  6. nyoj496巡回赛-拓扑排序-拓扑序列
  7. 使用easyUI 格式化datagrid列
  8. iOS 10 的一个重要更新-自定义的通知界面
  9. android webview测速,学习分享,echarts模拟宽带测速效果 附Demo演示地址!!
  10. (35)Verilog HDL算术运算:取模、指数、对数
  11. hdu 1710 Binary Tree Traversals (二叉树)
  12. SVN下载项目到本地
  13. 光学动作捕捉系统构成
  14. 怎么关闭服务器系统自动更新,自动更新怎么关闭 如何关闭window自动更新提高运行速度...
  15. acm会议什么档次_国际顶级会议期刊级别介绍
  16. JS数组方法最全最详细总结
  17. 作文第一次用计算机350,第一次作文350字
  18. Conda 镜像站配置
  19. 网易互娱2017实习生招聘在线笔试--源代码编译
  20. 出场、入场动画大全,基于NineOldAndroids轻松实现动画效果

热门文章

  1. vue 环境的搭建及初始化项目
  2. Laravel 不同环境加载不同的.env文件
  3. React使用的扩展
  4. 1058. 选择题(20)
  5. WinDbg 查看静态变量
  6. MyBatis操作指南-与Spring集成(基于注解)
  7. jquery GET POST
  8. centos7.2下编译安装git
  9. 如何从 Datagrid 中获得单元格的内容与 使用值转换器进行绑定数据的转换IValueConverter...
  10. 调整Tomcat上的参数提高性能[转]