2A codeforces - Winner
http://codeforces.com/problemset/problem/2/A
Solution in C++
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pii pair<int,int>
int n,val,mx=-2000000,nn;
map<string,int> all,all2;
string nam,winn;
vector<pair<string,int> > time_line;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;nn=n;
while(n-- && cin>> nam >> val ){all[nam]+=val;time_line.push_back({nam,val});}
for(auto u : all)mx=max(mx,u.second);
for(int u=0;u<nn;u++)
{
nam=time_line[u].first;
val=time_line[u].second;
all2[nam]+=val;
if(all2[nam]>=mx && all[nam]==mx)
{
cout<<nam;
return 0;;
}
}
return 0;
}
0 التعليقات:
إرسال تعليق