Codeforces Round #2A Winner

来源:互联网 发布:淘宝店铺动态 编辑:程序博客网 时间:2024/04/28 21:16
#include <iostream>#include <map>#include <string>using namespace std;const int maxn = 1005;int score[maxn];string name[maxn];int main(){int n;while (cin >> n) {map<string, int> m;for (int i = 0; i < n; ++i) {cin >> name[i] >> score[i];m[name[i]] += score[i];score[i] = m[name[i]];}map<string, int>::iterator it;int maxscore = -1e9;for (it = m.begin(); it != m.end(); ++it) {if ((*it).second > maxscore) maxscore = (*it).second;}int pos = 0;for (int i = 0; i < n; ++i) {if (m[name[i]] == maxscore && score[i] >= maxscore) {pos = i;break;}}cout << name[pos] << endl;}return 0;}

0 0