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 <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

class Group {
    public:
    vector<int> memberIndexes;

    Group(){}
    
    void add(int x){memberIndexes.push_back(x);}
    int size(){return (memberIndexes.size());}
    
    bool operator < (Group rhs){
        return this->size() < rhs.size();
    }
};

int main(){
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}
        // put into groups that can be removed together
        // minimize groups
        // groups are contigous seperated by lower numbers
        // for each number store group (what information about the group. indexes? l and r of range. )
        // we need to store the amount of members of each group, and an arr of the locations (and thus the range)
        vector<int> numArr;
        unordered_map<int, int> numNums;
        for (int i : arr){
            if (numNums.count(i)) { 
                (numNums[i] += 1);
            } else {
                numNums[i] = 1;
                numArr.push_back(i);


            }
        }
        vector<int> amtNums;
        for (int i : numArr){amtNums.push_back(numNums[i]);}
        sort(amtNums.begin(), amtNums.end());
        int groupsRmed = 0;
        for (int i : amtNums){
            k -= i;
            if (k < 0){
                break;
            } else {
                groupsRmed++;


            }
        }
        int res = (size(numArr) - groupsRmed != 0) ? (size(numArr) - groupsRmed) : 1;
        cout << res << "\n";
        







    }
}


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main(){
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int c; cin >> c;
    while(c--){
        int n, k;
        cin >> n >> k;
        vector<int> arr;
        for (int i = 0; i < n; i++){int tmp; cin >> tmp; arr.push_back(tmp);}
        // put into groups that can be removed together
        // minimize groups
        // groups are contigous seperated by lower numbers
        // for each number store group (what information about the group. indexes? l and r of range. )
        // we need to store the amount of members of each group, and an arr of the locations (and thus the range)
        vector<int> numArr;
        unordered_map<int, int> numNums;
        for (int i : arr){
            if (numNums.count(i)) { 
                (numNums[i] += 1);
            } else {
                numNums[i] = 1;
                numArr.push_back(i);


            }
        }
        vector<int> amtNums;
        for (int i : numArr){amtNums.push_back(numNums[i]);}
        sort(amtNums.begin(), amtNums.end());
        int groupsRmed = 0;
        for (int i : amtNums){
            k -= i;
            if (k < 0){
                break;
            } else {
                groupsRmed++;


            }
        }
        int res = (size(numArr) - groupsRmed != 0) ? (size(numArr) - groupsRmed) : 1;
        cout << res << "\n";
        







    }
}