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

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#include <cmath>
#include <cstddef>
#define Mahmoud ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define Ef(i,x,n) for(int i=x;i<=n;i++)
#define If(i,x,n,inc) for(int i=x;i<n;i+=inc)
#define Rf(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define pf push_front
#define b_e(v) v.begin(),v.end()
#define rb_e(v) v.rbegin(),v.rend()
#define xD 0
using namespace std;
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
const ll MAX=1e5+5;

int main() {
    Mahmoud
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--){
        int n,k,a[MAX];
        cin>>n>>k;
        unordered_map<int,int>mp;
        for(int i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        vector<int>cnt;
        cnt.reserve(mp.size());
        for(auto &p:mp)cnt.pb(p.second);
        sort(b_e(cnt),greater<int>());

        if(n-cnt[0]<=k){
            cout<<1<<endl;
            continue;
        }
        int d=0,sm=0;
        for(int x:cnt){
            sm+=x;
            d++;
            if(n-sm<=k)break;
        }
        cout<<d<<endl;

    }
    return xD;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <cmath>
#include <cstddef>
#define Mahmoud ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define Ef(i,x,n) for(int i=x;i<=n;i++)
#define If(i,x,n,inc) for(int i=x;i<n;i+=inc)
#define Rf(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define pf push_front
#define b_e(v) v.begin(),v.end()
#define rb_e(v) v.rbegin(),v.rend()
#define xD 0
using namespace std;
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
const ll MAX=1e5+5;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};int main() {
    Mahmoud
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t;
    cin>>t;
    while(t--){
        int n,k,a[MAX];
        cin>>n>>k;
        unordered_map<int,int,custom_hash>mp;
        for(int i=0;i<n;i++){
            cin>>a[i];
            mp[a[i]]++;
        }
        vector<int>cnt;
        cnt.reserve(mp.size());
        for(auto &p:mp)cnt.pb(p.second);
        sort(b_e(cnt),greater<int>());

        if(n-cnt[0]<=k){
            cout<<1<<endl;
            continue;
        }
        int d=0,sm=0;
        for(int x:cnt){
            sm+=x;
            d++;
            if(n-sm<=k)break;
        }
        cout<<d<<endl;

    }
    return xD;
}