Skip to content

Instantly share code, notes, and snippets.

@vumbumy
Created October 13, 2016 02:55
Show Gist options
  • Select an option

  • Save vumbumy/4fca77ed3102b8781b5fbfea0514d00d to your computer and use it in GitHub Desktop.

Select an option

Save vumbumy/4fca77ed3102b8781b5fbfea0514d00d to your computer and use it in GitHub Desktop.
#pragma warning(disable:4996)
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <stdio.h>
using namespace std;
bool A(const pair<int, pair<int,int> >& l, const pair<int, pair<int, int> >& r) {
if (l.second.first == r.second.first)
return l.second.second > r.second.second;
return l.second.first > r.second.first;
}
int main()
{
unordered_map<int, pair<int,int>> m;
int t, n; cin >> t >> n;
while (t--)
{
cin >> n;
m[n].first++;
m[n].second = max(m[n].second,t);
}
vector<pair<int, pair<int,int> > > v(m.begin(), m.end());
sort(v.begin(), v.end(), &A);
for (auto it : v) {
for (int i = 0; i < it.second.first; i++)
cout << it.first << " ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment