Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define v(n) vector<ll> v(n)
#define inp(n) for(ll i=0;i<n;++i){ cin>>v[i]; }
#define op(n) for(ll i=0;i<v.size();++i){ cout<<v[i]<<" ";}
#define yes cout<<"Yes"
#define no cout<<"No"
#define br break
#define cnti continue
#define nl cout<<endl
#define all v.begin(),v.end()

 int gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b);}

 int power(ll a,ll b){if(b==0) return 1;ll res =power(a,b/2);
    if(b&1){
        return a*res*res;
    }else{
        return res*res;
    }
 }

 bool prime(ll n){
     bool t = true;
     for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            t=false;
            break;
        }
     }
     return t;
 }
ll min(ll a,ll b){
    return a>b ? b: a;
}

const int n1=1e9+7;

bool isBinaryString(const string& str) {
    return all_of(str.begin(), str.end(), [](char c) { return c == '0' || c == '1'; });
}
void solve(){

 ll n,k;cin>>n>>k;
 vector<ll> a;

map<ll,ll> m;
 for(int i=0;i<n;i++){
    ll p;cin>>p;
    a.push_back(p);
    m[p]++;
 }
//  nl;
// for(auto it: m){
//     cout<<it.first<<" "<<it.second;nl;
// }

map<ll,ll> am;
for(auto it: m){
    am[it.second]++;
}
// nl;
// for(auto it:am){
//     cout<<it.first<<" "<<it.second;nl;
// }

ll ans=m.size();
for(auto it: am){
   ll x=it.first;
   if(k>0){
        if(k>x*it.second){
            ans-=x*it.second;
            k-=x*it.second;
        }else{
            if(k==x*it.second){
                ans-=it.second;
                k=0;
            }else{
                ans-=(k/x);
                k=0;
            }
        }
   }else{
    if(ans<1){
        cout<<"1";nl;return ;
    }else{
        cout<<ans;nl;return ;
    }
   }
}
if(ans<1){
    cout<<"1";nl;return ;
}else{
    cout<<ans;nl;return ;
}

}
    


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
   ll t;cin>>t;
  while(t--) solve();
  return 0;
   }
  

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define v(n) vector<ll> v(n)
#define inp(n) for(ll i=0;i<n;++i){ cin>>v[i]; }
#define op(n) for(ll i=0;i<v.size();++i){ cout<<v[i]<<" ";}
#define yes cout<<"Yes"
#define no cout<<"No"
#define br break
#define cnti continue
#define nl cout<<endl
#define all v.begin(),v.end()

 int gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b);}

 int power(ll a,ll b){if(b==0) return 1;ll res =power(a,b/2);
    if(b&1){
        return a*res*res;
    }else{
        return res*res;
    }
 }

 bool prime(ll n){
     bool t = true;
     for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            t=false;
            break;
        }
     }
     return t;
 }
ll min(ll a,ll b){
    return a>b ? b: a;
}

const int n1=1e9+7;

bool isBinaryString(const string& str) {
    return all_of(str.begin(), str.end(), [](char c) { return c == '0' || c == '1'; });
}
void solve(){

 ll n,k;cin>>n>>k;
 vector<ll> a;

map<ll,ll> m;
 for(int i=0;i<n;i++){
    ll p;cin>>p;
    a.push_back(p);
    m[p]++;
 }

 vector<pair<ll,ll>>am;
 for(auto it: m){
    am.push_back({it.second,it.first});
 }
 sort(am.begin(),am.end());
 ll cnt=0;

for(int i=0;i<am.size();i++){
    if(k>=am[i].first){
       k=k-am[i].first;
       cnt++;
    }else{
        break;
    }
}
if(m.size()-cnt<1){
    cout<<"1";nl;return ;
}else{
    cout<<m.size()-cnt;nl;return ;
}

}
    


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
   ll t;cin>>t;
  while(t--) solve();
  return 0;
   }