Advertisement
alexOloieri

Untitled

Nov 19th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define inf 999999999
  3. using namespace std;
  4.  
  5. int n, p, maxx = -inf, early = inf;
  6. string act, ans;
  7. map<string,int>points;
  8. map<string,vector<pair<int,int>>>history;
  9. vector<string>candidates;
  10.  
  11. int main()
  12. {
  13.     cin>>n;
  14.     for (int i=1;i<=n;++i)
  15.     {
  16.         cin>>act>>p;
  17.         points[act] += p;
  18.         history[act].push_back(make_pair(points[act],i));
  19.     }
  20.     for (auto x:points)
  21.     {
  22.         if (x.second > maxx)
  23.         {
  24.             candidates.clear();
  25.             maxx = x.second;
  26.             candidates.push_back(x.first);
  27.         }
  28.         else
  29.         if (x.second == maxx)
  30.             candidates.push_back(x.first);
  31.     }
  32.     if (candidates.size() == 1)
  33.         cout<<candidates[0]<<'\n';
  34.     else
  35.     {
  36.         for (auto y:candidates)
  37.         {
  38.             for (auto x:history[y])
  39.             {
  40.                 if (x.first >= maxx && x.second < early)
  41.                     ans = y, early = x.second;
  42.             }
  43.         }
  44.         cout<<ans<<'\n';
  45.     }
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement