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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <iterator>

using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define debug(x) cerr << #x << " = " << (x) << endl;
#define NN cout << '\n'
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

//************************************************************************************
//************************************************************************************

int32_t main()
{
    FAST int t = 1;
    int C = 1;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        int ans = 0;
        if(n==k){
            cout<<1;
            NN;
            continue;
        }
        map<int, int> freq;
        priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;

        int x;
        for (int i = 0; i < n; i++)
        {
            cin >> x;
            freq[x]++;
        }
        for (auto i = freq.begin(); i != freq.end(); i++)
        {
            pq.push(mp(i->ss, i->ff));
            ans++;
        }

        while (k && pq.size()>1)
        {
            int cur = pq.top().first;
            int s=pq.top().ss;
            if (k >= cur)
            {
                k -= cur;
                ans--;
                pq.pop();
            }
            else
                break;
        }
        // cout << ans;
        cout<<pq.size();
        NN;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <iterator>

using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define debug(x) cerr << #x << " = " << (x) << endl;
#define NN cout << '\n'
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

//************************************************************************************
//************************************************************************************

int32_t main()
{
    FAST int t = 1;
    int C = 1;
    cin >> t;
    while (t--)
    {
        int n, k;
        cin >> n >> k;
        int ans = 0;
        map<int, int> freq;

        int x;
        for (int i = 0; i < n; i++)
        {
            cin >> x;
            freq[x]++;
        }
        if(n==k){
            cout<<1;
            NN;
            continue;
        }
        priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
        for (auto i = freq.begin(); i != freq.end(); i++)
        {
            pq.push(mp(i->ss, i->ff));
            ans++;
        }

        while (k && pq.size()>1)
        {
            int cur = pq.top().first;
            int s=pq.top().ss;
            if (k >= cur)
            {
                k -= cur;
                ans--;
                pq.pop();
            }
            else
                break;
        }
        // cout << ans;
        cout<<pq.size();
        NN;
    }
    return 0;
}