Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4. #include <map>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int n;
  12.     cin >> n;
  13.     vector<int> m;
  14.     unordered_map<int, pair<int, int>> start_end;
  15.     map<int, int> inners;
  16.     for (int i(0); i < n; ++i) {
  17.         start_end[i] = make_pair(-1, -1);
  18.     }
  19.     for (int i(0); i < n; ++i){
  20.         int temp;
  21.         cin >> temp;
  22.         m.push_back(temp);
  23.         inners[temp]++;
  24.         if (start_end[i].first == -1) {
  25.             start_end[i].first = i;
  26.         }
  27.         else {
  28.             start_end[i].second = 1;
  29.         }
  30.     }
  31.     int a, b;
  32.     auto it = inners.rbegin();
  33.     a = (*it).second;
  34.     b = (*next(it)).second;
  35.     int l((*it).first), r((*next(it)).first);
  36.     it++;
  37.     while ((a == b) && (it != inners.rend())) {
  38.         if (start_end[(*it).first].second - start_end[(*it).first].first > start_end[(*next(it)).first].second - start_end[(*next(it)).first].first) {
  39.             l = (*it).first;
  40.             r = (*(next(it))).first;
  41.         }
  42.         a = (*it).second;
  43.         b = (*++it).second;
  44.     }
  45.     cout << l << " " << r;
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement