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

Previous submission (verdict: Time limit exceeded on test 13):
// This program is made by sujal Vekariya
#include <bits/stdc++.h>
using namespace std;

#define fastio()                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define trav(x, v) for (auto &x : v)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define mod 1000000007
#define inf INT_MAX
#define minf INT_MIN
#define desync() cout.flush(), system("pause"), _Exit(0)

ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}

bool is_prime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (ll i = 5; i * i <= n; i += 6)
    {
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }
    return true;
}

int main()
{
    fastio();
    int t;
    cin >> t;
    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        vll a(n);

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        if(k>=n)
        {
            cout<<1<<endl;
            continue;
        }
        unordered_map<ll, ll> freq;
        for (int i = 0; i < n; i++)
        {
            freq[a[i]]++;
        }

        vector<ll> freq_values;
        for (auto it : freq)
        {
            freq_values.push_back(it.second);
        }
        sort(freq_values.begin(), freq_values.end());

        int distinct_count = freq.size();
        for (ll f : freq_values)
        {
            if (k >= f)
            {
                k -= f;
                distinct_count--;
            }
            else
            {
                break;
            }
        }

        cout << distinct_count << endl;
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 11):
// This program is made by sujal Vekariya
#include <bits/stdc++.h>
using namespace std;

#define fastio()                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define trav(x, v) for (auto &x : v)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define mod 1000000007
#define inf INT_MAX
#define minf INT_MIN
#define desync() cout.flush(), system("pause"), _Exit(0)

ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}

bool is_prime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (ll i = 5; i * i <= n; i += 6)
    {
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }
    return true;
}

int main()
{
    fastio();
    int t;
    cin >> t;
    while (t--)
    {
        ll n, k;
        cin >> n >> k;
        ll x;
        unordered_map<ll, ll> freq;

        for (int i = 0; i < n; i++)
        {
            cin >> x;
            freq[x]++;
        }
        if(k>=n)
        {
            cout<<1<<endl;
            continue;
        }
        
        vector<ll> freq_values;
        for (auto it : freq)
        {
            freq_values.push_back(it.second);
        }
        sort(freq_values.begin(), freq_values.end());

        int distinct_count = freq.size();
        for (ll f : freq_values)
        {
            if (k >= f)
            {
                k -= f;
                distinct_count--;
            }
            else
            {
                break;
            }
        }

        cout << distinct_count << endl;
    }

    return 0;
}