deushiro

Untitled

Mar 12th, 2020
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.     vector<int> a(101);
  10.     priority_queue<pair<int, int>> q;
  11.     for(int i = 0; i < n; ++i){
  12.         int x;
  13.         cin >> x;
  14.         a[x]++;
  15.     }
  16.     for(int i = 0; i < a.size(); ++i){
  17.         if(a[i])
  18.             q.push({a[i], i});
  19.     }
  20.     vector<int> ans;
  21.     while(q.size()){
  22.         int x = q.top().first;
  23.         int y = q.top().second;
  24.         q.pop();
  25.         if(ans.size() && ans.back() == y && q.size()){
  26.             int u = q.top().first;
  27.             int v = q.top().second;
  28.             q.pop();
  29.             ans.push_back(v);
  30.             u--;
  31.             if(u)
  32.                 q.push({u, v});
  33.         }
  34.         else{
  35.             ans.push_back(y);
  36.             x--;
  37.         }
  38.         if(x)
  39.             q.push(make_pair(x, y));
  40.     }
  41.     int maxi = 0;
  42.     int res = 0;
  43.     for(int i = 1; i < n; ++i){
  44.         if(ans[i] == ans[i - 1])
  45.             res++;
  46.         else{
  47.             maxi = max(res, maxi);
  48.             res = 0;
  49.         }
  50.     }
  51.     maxi = max(res, maxi);
  52.     cout << maxi << endl;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment