Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include<bits//stdc++.h>
  2. #define RIP(i,a,b) for(int i = a; i < b; i++)
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(0);
  8.     cin.tie(0);
  9.     cout.tie(0);
  10.     int n;
  11.     cin >> n;
  12.     vector<int> a;
  13.     vector< pair<int, int> > b;
  14.     RIP(i,0,n)
  15.     {
  16.         int x;
  17.         cin >> x;
  18.         a.push_back(x);
  19.         int l = 0, r = b.size();
  20.         while(r - l > 1)
  21.         {
  22.             int m = (l + r)/2;
  23.             if(b[m].first > x)
  24.                 r = m;
  25.             else
  26.                 l = m;
  27.         }
  28.         if(b[l].first == x)
  29.             b[l].second += 1;
  30.         else if(b[r].first == x)
  31.             b[r].second += 1;
  32.         else
  33.         b.insert(b.begin() + l, {x, 1});
  34.     }
  35.     int mx = 0, mxn;
  36.  
  37.     for(auto u: b)
  38.     {
  39.         if(u.second > mx)
  40.         {
  41.             mx = u.second;
  42.             mxn = u.first;
  43.         }
  44.     }
  45.     RIP(i,0,n)
  46.     {
  47.         if(a[i] != mxn)
  48.             cout << a[i];
  49.     }
  50.     RIP(i,0,mx)
  51.         cout << mxn;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement