Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Atcoder Beginner Contest 201 Problem B Solution
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int n;
- cin >> n;
- vector<pair<string, int>> mountains(n);
- for (auto& mountain: mountains) {
- cin >> mountain.first >> mountain.second;
- }
- pair<string, int> first_max = mountains[0];
- pair<string, int> second_max = mountains[1];
- if (mountains[1].second > mountains[0].second) {
- first_max = mountains[1];
- second_max = mountains[0];
- }
- for (int i = 2; i < mountains.size(); i++) {
- if (mountains[i].second > first_max.second) {
- //mountains[i].second > first_max.second > second_max.
- second_max = first_max;
- first_max = mountains[i];
- } else {
- if (mountains[i].second > second_max.second) {
- second_max = mountains[i];
- }
- }
- }
- cout << second_max.first << endl;
- //Time complexity: O(N)
- }
- ~
Advertisement
Add Comment
Please, Sign In to add comment