Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <unordered_map>
- #include <map>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> m;
- unordered_map<int, pair<int, int>> start_end;
- map<int, int> inners;
- for (int i(0); i < n; ++i) {
- start_end[i] = make_pair(-1, -1);
- }
- for (int i(0); i < n; ++i){
- int temp;
- cin >> temp;
- m.push_back(temp);
- inners[temp]++;
- if (start_end[i].first == -1) {
- start_end[i].first = i;
- }
- else {
- start_end[i].second = 1;
- }
- }
- int a, b;
- auto it = inners.rbegin();
- a = (*it).second;
- b = (*next(it)).second;
- int l((*it).first), r((*next(it)).first);
- it++;
- while ((a == b) && (it != inners.rend())) {
- if (start_end[(*it).first].second - start_end[(*it).first].first > start_end[(*next(it)).first].second - start_end[(*next(it)).first].first) {
- l = (*it).first;
- r = (*(next(it))).first;
- }
- a = (*it).second;
- b = (*++it).second;
- }
- cout << l << " " << r;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement