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

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.