Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> a(101);
- priority_queue<pair<int, int>> q;
- for(int i = 0; i < n; ++i){
- int x;
- cin >> x;
- a[x]++;
- }
- for(int i = 0; i < a.size(); ++i){
- if(a[i])
- q.push({a[i], i});
- }
- vector<int> ans;
- while(q.size()){
- int x = q.top().first;
- int y = q.top().second;
- q.pop();
- if(ans.size() && ans.back() == y && q.size()){
- int u = q.top().first;
- int v = q.top().second;
- q.pop();
- ans.push_back(v);
- u--;
- if(u)
- q.push({u, v});
- }
- else{
- ans.push_back(y);
- x--;
- }
- if(x)
- q.push(make_pair(x, y));
- }
- int maxi = 0;
- int res = 0;
- for(int i = 1; i < n; ++i){
- if(ans[i] == ans[i - 1])
- res++;
- else{
- maxi = max(res, maxi);
- res = 0;
- }
- }
- maxi = max(res, maxi);
- cout << maxi << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment