Codeforces Round #781 (Div. 2)
Problem Link: https://codeforces.com/contest/1665/problem/C
Solution in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a, n,t,i,j,c,ans,v,x;
    cin>>t;
    while(t--)
    {
        map<long long,long long>mp;
        vector<long long>v;
        priority_queue<long long>pq;
        v.push_back(1);
        c=0,ans=0;
        cin>>n;
        for(i=0; i<n-1; i++)
        {
            cin>>a;
            mp[a]++;
        }
        for(auto j:mp)
        {
            v.push_back(j.second);
        }
        sort(v.begin(),v.end());
        ans=v.size();
        for(i=0; i<v.size(); i++)
        {
            int  m=v[i];
            m-=i+1;
            if(m>0)
                pq.push(m);
        }
        while(!pq.empty())
        {
            int m=pq.top();
            pq.pop();
            if(m<=c)break;
            m--;
            c++;
            ans++;
               pq.push(m);
        }
        cout<<ans<<endl;
    }
}
 


 

No comments