Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
//Hara Hara Mahadev
#include<bits/stdc++.h>
using namespace std;
 
#define int 	long long
#define pi      3.1415926535897932384626433832795028841971693993751058
#define YES     cout<<"YES"<<"\n"
#define NO      cout<<"NO"<<"\n"
#define m1      cout<<-1<<"\n"
#define ssort(S)  sort((S).begin(),(S).end())
#define srev(S)   reverse((S).begin(),(S).end())
#define ll      long long
#define pb      push_back
#define vi      vector<int>
#define vvi 	vector<vector<int>>
#define vll      vector<long long>
#define vc      vector<char>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int>>
#define vs	 vector<string>
#define all(arr)  (arr).begin(), (arr).end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define inp(v) for (auto & a : (v)) cin >> a;
#define endl "\n"
#define speed (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define mod 1000000007
 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  

int ceil_div(int a, int b) {
   return a / b + ((a ^ b) > 0 && a % b != 0);
}

void solve()
{
   int n,k;
   cin >> n >> k;

   unordered_map<int,int> mpp;
   for0(i, n) {
        int x; cin >> x; mpp[x]++;
   }

   priority_queue<pii, vpii, greater<pii>> pq;
   for(auto [ele, f]: mpp)
        pq.push({f, ele});

    while(!pq.empty() && k>0) {
        auto it = pq.top();
        pq.pop();
        int f = it.first;
        if(f>k) {
            pq.push(it);
            break;
        }
        else {
            k -= f;
        }
    }

    cout << max(1,pq.size()) << endl;
}

int t = 1;
int32_t main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cin>>t;
    //cin >> t;
    while(t--){solve();}
    return 0;
}

Submission (verdict: Time limit exceeded on test 14):
//Hara Hara Mahadev
#include<bits/stdc++.h>
using namespace std;
 
#define int 	long long
#define pi      3.1415926535897932384626433832795028841971693993751058
#define YES     cout<<"YES"<<"\n"
#define NO      cout<<"NO"<<"\n"
#define m1      cout<<-1<<"\n"
#define ssort(S)  sort((S).begin(),(S).end())
#define srev(S)   reverse((S).begin(),(S).end())
#define ll      long long
#define pb      push_back
#define vi      vector<int>
#define vvi 	vector<vector<int>>
#define vll      vector<long long>
#define vc      vector<char>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int>>
#define vs	 vector<string>
#define all(arr)  (arr).begin(), (arr).end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define inp(v) for (auto & a : (v)) cin >> a;
#define endl "\n"
#define speed (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define mod 1000000007
 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  

int ceil_div(int a, int b) {
   return a / b + ((a ^ b) > 0 && a % b != 0);
}

void solve()
{
   int n,k;
   cin >> n >> k;


   unordered_map<int,int> mpp;
   for0(i, n) {
        int x; cin >> x; mpp[x]++;
   }

  vi arr;
   for(auto [ele, f]: mpp)
        arr.pb(f);

    sort(all(arr));
    int sum = 0;
    int sz = arr.size();

    for(int i=0; i<sz; i++) {
        if(sum + arr[i] <= k)
            sum += arr[i];
        else {
            cout << max(1, sz-i) << endl;
            return;
        }

    }
    cout << "1" << endl;
}

int t = 1;
int32_t main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cin>>t;
    //cin >> t;
    while(t--){solve();}
    return 0;
}