-
Notifications
You must be signed in to change notification settings - Fork 0
/
2A.cpp
127 lines (61 loc) · 1.24 KB
/
2A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main()
{
map<string,int> mp;
map<string,int> mp1;
int n;
cin>>n;
string name;
vector<pair<string,int> > data;
vector<string> namel;
int mx=INT_MIN;
while(n--)
{
string s;
int sc;
cin>>s>>sc;
data.push_back({s,sc});
if(mp.find(s) == mp.end())
{
namel.push_back(s);
mp[s]=sc;
mp1[s]=0;
}
else
{
mp[s]+=sc;
}
}
vector<string> mxn;
for(int i=0;i<namel.size();i++)
{
if(mp[namel[i]]>mx)
mx=mp[namel[i]];
}
for(int i=0;i<namel.size();i++)
{
if(mp[namel[i]]==mx)
mxn.push_back(namel[i]);
}
if(mxn.size()==1)
{
cout<<mxn[0];
return 0;
}
int sc;
string s;
for(int i=0;i<data.size();i++)
{
s=data[i].first;
sc=data[i].second;
mp1[s]+=sc;
if(mp1[s]>=mx && mp[s]==mx)
{
cout<<s;
return 0;
}
}
}