Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 140 ms):
#include <bits/stdc++.h>
using namespace std;
 
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> index_set;
//typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>indexed_multiset;
 
typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lld;
 
#define MOD         1000000007
#define MOD1        998244353
#define pi          3.14159265358979323846
#define N           100005
#define sz(x)       ((int)(x).size())
#define test ll t;  cin >> t; while(t--)
#define all(x)      (x).begin(), (x).end()
#define bigint      int64_t
#define vll         vector<ll>
#define vpll        vector<pair<ll,ll>>
#define pb          push_back
#define pll         pair<ll,ll>
#define vvll        vector<vector<ll>>
#define fi          first
#define se          second
#define endl        "\n"
#define rep(i,a,n)  for(ll (i) = a;(i) < (n); (i)++)
#define repn(i,a,n) for(ll (i) = a;(i) <= (n); (i)++)
#define repr(i,a,n) for(ll (i) = a;(i) >= (n); (i)--)
 
#define debug2(x,y)  cerr << "Line ("<< __LINE__ << ") " << #x <<" : "<<x<<", "<<#y<<" : "<<y<< endl;
#define debug3(x,y,z)cerr << "Line ("<< __LINE__ << ") " << #x <<" : "<<x<<", "<<#y<<" : "<<y<<", "<<#z<<" : "<<z<< endl;
 
 
//-------------------DEBUGGING-----------------------
 
void  google(int t)    {cout << "Case #" << t << ": ";}
void _print(ll t)      {cerr << t;}
void _print(int t)     {cerr << t;}
void _print(string t)  {cerr << t;}
void _print(char t)    {cerr << t;}
void _print(lld t)     {cerr << t;}
void _print(double t)  {cerr << t;}
void _print(ull t)     {cerr << t;}
 
 
template <class T, class V>         void _print(pair <T, V> p);
template <class T>                  void _print(vector <T> v);
template <class T>                  void _print(set <T> v);
template <class T, class V>         void _print(map <T, V> v);
template <class T>                  void _print(multiset <T> v);
template <class T, class V>         void _print(pair <T, V> p) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.se); cerr << "}";}
template <class T>                  void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T>                  void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T>                  void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V>         void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
// void _print(pbds v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
 
 
#ifdef XOX
#define debug(x) cerr << "Line ("<< __LINE__ << ") " << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
 
//-----------------------------------------------------------------------
 
 
void solve() {
    test{
        int n, k; cin >> n >> k;

        map<int,int> mp;
        for(int i = 0; i < n; i++){
            int x;
            cin >> x;
            mp[x]++;
        }
        int temp = k;
        vector<pair<int, int>> v;
        for(auto it: mp){
            v.push_back({it.second, it.first});
        }

        sort(v.begin(), v.end());

        int cnt = 0;
        for(auto it: v){
            if(k > 0){
                if(k >= it.first){
                    cnt++;
                    k -= it.first;
                }

            }
        }
        if(temp == 0 ){
            cout << v.size() << endl;
        } else {
            cout << max(1, int(v.size()) - cnt) << endl;
        }
    }
}
 
 
int main() {
 
//#ifdef XOX
//    freopen("/home/khoya_musafir/Desktop/cp/env/output.txt", "w", stderr);
//#endif
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    solve();
    return 0;
}

Solution 2 (runtime: 218 ms):
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void print(vector<int> v1)
{
    cout<<"Printing The array"<<endl;
    for(int i=0; i<v1.size(); ++i)
    {
        cout<<v1[i]<<" ";
    }
    cout<<"\n";
}
int solve()
{
    int n, k;
    cin>>n>>k;
    vector <int> b;
    for(int j = 0; j<n; ++j)
    {
        int value;
        cin>>value;
        b.push_back(value);
    }
    //print(b);
    sort(b.begin(), b.end());
    //print(b);
    vector<int> count = {1};
    
    for(int j = 1; j<n; ++j)
    {
        if(b[j - 1] == b[j])
        {
            ++count.back();
        }
        else
        {
            count.emplace_back(1);
        }
    }
    //print(count);
    sort(count.begin(), count.end());
    //print(count);
    for(int m = 0; m<count.size() - 1; ++m)
    {
        if(count[m] > k)
        {
            return count.size() - m;
        }
        else
        {
            k = k - count[m];
        }
    }
    return 1;
}
int main()
{
    int t;
    cin>>t;

    for(int i=0; i<t ; ++i)
    {
        int ans = solve();
        cout<<ans<<endl;
    }
}