Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
/******************************************************************************

Welcome to GDB Online.
  GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
  C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
  Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;
        vector<pair<int, int>> v(n);

        for (int i = 0; i < n; i++) {
            cin >> v[i].ff >> v[i].ss;
        }

        unordered_map<int, int> mpp;
        vector<int> single_digits;

        for (int i = 0; i < n; i++) {
            if (v[i].ff - v[i].ss == 0 && mpp.find(v[i].ff) == mpp.end()) {
                single_digits.pb(v[i].ff);
            }
            if ((v[i].ff - v[i].ss) == 0) {
                mpp[v[i].ff]++;
            }
        }

        sort(single_digits.begin(), single_digits.end());
        int m = single_digits.size();
        string res = "";

        for (int i = 0; i < n; i++) {
            if (v[i].ss - v[i].ff >= 1) {
                int lower_bound = -1;
                int low = 0;
                int high = m - 1;
                
                while (low <= high) {
                    int mid = (low + high) / 2;
                    if (single_digits[mid] > v[i].ff) {
                        high = mid - 1;
                    } else {
                        lower_bound = mid;
                        low = mid + 1;
                    }
                }

                low = 0;
                high = m - 1;
                int upper_bound = -1;

                while (low <= high) {
                    int mid = (low + high) / 2;
                    if (single_digits[mid] <= v[i].ss) {
                        low = mid + 1;
                        upper_bound = mid;
                    } else {
                        high = mid - 1;
                    }
                }

                if (lower_bound == -1 || upper_bound == -1 ||
                    single_digits[lower_bound] != v[i].ff ||
                    single_digits[upper_bound] != v[i].ss ||
                    (upper_bound - lower_bound + 1) != (v[i].ss - v[i].ff + 1)) {
                    res.push_back('1');
                } 
                else {
                    res.push_back('0');
                }
            } 
            else {
                if (mpp[v[i].ff] > 1) {
                    res.push_back('0');
                } 
                else {
                    res.push_back('1');
                }
            }
        }

        cout << res << endl;
    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 11):
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define Code ios_base::sync_with_stdio(false);
#define By cin.tie(NULL);
 
int main()
{
    int T;
    cin >> T;
    while (T--) {
        int n, k;
        cin>>n>>k;
        vector<int>a(n);
        for(int i =0  ; i < n ; i++){
            cin>>a[i];
        }
        unordered_map<int , int>mpp;
        for(int i =0 ; i < n ; i++){
            mpp[a[i]]++;
        }
        vector<int>freq;
        for(auto p : mpp){
            freq.push_back(p.second);
        }
        sort(freq.begin(), freq.end());
        int min_req = 0 ;
        int cnt = k;
        int res = 0;
        int m = freq.size();
        for(int i = 0 ; i < m ; i++){
            if(cnt>=freq[i]){
                cnt-=freq[i];
            }
            else{
                res++;
            }
        }
        if(res == 0 ){
            res =1 ;
        }
        cout<<res<<endl;
    }

    return 0;
}