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

Solution 1 (runtime: 233 ms):
#include<bits/stdc++.h>
using namespace std;
#define mAx(v) *max_element(v.begin(), v.end())
#define mIn(v) *min_element(v.begin(), v.end())
#define sUm(v) accumulate(v.begin(),v.end(),0LL)
#define yes cout << "YES" << endl
#define no cout<<"NO"<<endl
#define asort(v) sort(v.begin(),v.end())
#define dsort(v) sort(v.begin(),v.end(),greater<int>())
#define pb push_back
#define int  long long 
#define vi(v,n) vector<long long>v(n)
#define vp(v,n) vector<pair<long long,long long>>v(n)
#define take_p(v,n) vector<pair<long long ,long long>>v(n); for(long long i=0;i<n;i++){long long x,y;cin>>x>>y;v[i]={x,y};}
#define take(n) long long  n; cin>>n;
#define lf(i,a,n) for(int i=a;i<n;i++)
#define take_v(v,n) vector<long long >v(n); for(long long i=0;i<n;i++) cin>>v[i];
#define copy(a,b,n) for(int i=0;i<n;i++) a[i]=b[i];
#define unique(v) a.resize(unique(a.begin(), a.end()) - a.begin())
#define ub(v,k) auto it=upper_bound(a.begin(),a.end(),a[i]+n-1)-a.begin();
#define lb(v,k) auto it=lower_bound(a.begin(),a.end(),a[i]+n-1)-a.begin();
 
void solve(){
  int n,k;cin>>n>>k;
  vector<int>v(n);
  map<int,int>m;
  for(int i=0;i<n;i++){
    cin>>v[i];
    m[v[i]]++;
  }
 vector<int>p;
  for(auto it:m){
    p.push_back({it.second});
  }
  asort(p);
  int ans=1;
  int mark=0;
  for(int i=0;i<p.size();i++){
    if(k>=p[i]){
     k=k-p[i];
    }else{
      ans=max(ans,p.size()-i);
    }
  }
  cout<<ans<<endl;
 
}
 
 
int32_t main(){
take(t)
while(t--){
solve();
}
return 0;
}

Solution 2 (runtime: 125 ms):
#include <iostream>
#include <algorithm> // Ensure __gcd is recognized
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <unordered_map>
#include <cstring>
#include <climits>
#include <iomanip>
#include <numeric>
#include <map>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
const int MODD = 32768;
const int MOD = 1e9 + 7;
ll poww(int x, int n, int m)
{
    if (n == 0) return 1;
    ll u = poww(x, n / 2, m);
    u = (u * u) % m;
    if (n & 1) u = (u * x) % m;
    return u;
}
int fact(int n)
{
      if(n==0)
      return 1;
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = (res * i) % MOD;
    return res;
}
long nCr(int n, int r)
{
    return (poww(fact(n) / (fact(r) * fact(n - r)), MOD -1 , MOD));
}



void solve() {
  
    int n; cin >> n;
    int k; cin >> k;
    
    map<int, int> freq;
    for (int i = 0; i < n;i++)
    {
        int temp; cin >> temp;
        freq[temp]++;
    }
    int max_freq = 0;
    vector<pair<int, int>> pi;
    int pii = 0;
    int total_freq = freq.size();
    
    for (auto &it: freq)
    {
        pi.push_back({it.second, it.first});
       if (it.second > max_freq)
       {
            pii = it.first;
            max_freq = it.second;
       }
    }
    map<int, int> mp;
    mp[pii] = freq[pii];
    sort(pi.begin(), pi.end());
    for (auto &it: pi)
    {
        if (it.first <= k && k > 0 && pii != it.second)
        {
            mp[pii] += it.first;
            k -= it.first; 
        }
        else mp[it.second] = it.first;
    }
    cout << mp.size();
    label: cout << '\n';
    
}
int main() {
    fast;
    int t = 1;
   cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}