Guest User

ABC201 B Solution

a guest
Jun 3rd, 2021
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. //Atcoder Beginner Contest 201 Problem B Solution
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.   ios_base::sync_with_stdio(false);
  7.   cin.tie(NULL);
  8.   int n;
  9.   cin >> n;
  10.   vector<pair<string, int>> mountains(n);
  11.   for (auto& mountain: mountains) {
  12.       cin >> mountain.first >> mountain.second;
  13.   }
  14.   pair<string, int> first_max = mountains[0];
  15.   pair<string, int> second_max = mountains[1];
  16.   if (mountains[1].second > mountains[0].second) {
  17.       first_max = mountains[1];
  18.       second_max = mountains[0];
  19.   }
  20.   for (int i = 2; i < mountains.size(); i++) {
  21.       if (mountains[i].second > first_max.second) {
  22.           //mountains[i].second > first_max.second > second_max.
  23.           second_max = first_max;
  24.           first_max = mountains[i];
  25.       } else {
  26.           if (mountains[i].second > second_max.second) {
  27.               second_max = mountains[i];
  28.           }
  29.       }
  30.   }
  31.   cout << second_max.first << endl;
  32.   //Time complexity: O(N)
  33.  
  34.  
  35. }
  36. ~    
Advertisement
Add Comment
Please, Sign In to add comment