Guest User

Untitled

a guest
Jan 25th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main ()
  6.  
  7. {
  8.  
  9. map <string, long>h,m;
  10.  
  11. map <string, long>::iterator j;
  12.  
  13. int n, d[100009], once, max = -10000000;
  14.  
  15. string name[100009], winner;
  16.  
  17. cin >> n;
  18.  
  19. for (int i = 0; i < n; i++)
  20.  
  21. {
  22.  
  23. cin >> name[i] >> d[i];
  24.  
  25. h[name[i]] += d[i];
  26.  
  27. }
  28.  
  29. for ( j = h.begin(); j != h.end(); j++ )
  30.  
  31. if ( j -> second > max )
  32.  
  33. {
  34.  
  35. max = j -> second;
  36.  
  37. once = 1;
  38.  
  39. winner = j -> first;
  40.  
  41. }
  42.  
  43. else if ( j -> second == max)
  44.  
  45. once = 0;
  46.  
  47. if ( once )
  48.  
  49. cout << winner;
  50.  
  51. else {
  52.  
  53. for ( int i = 0; i < n; i++ )
  54.  
  55. {
  56.  
  57. m[name[i]] += d[i];
  58.  
  59. if ( m[name[i]] >= max && h[name[i]] == max )
  60.  
  61. {
  62.  
  63. cout << name[i];
  64.  
  65. break;
  66.  
  67. }
  68.  
  69. }
  70.  
  71. }
  72.  
  73. exit(0);
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment