ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long t;
    cin >> t;

    while (t--) {
        long long n, k;
        cin >> n >> k;
        vector<long long> array(n);
        for (long long i = 0; i < n; i++) {
            cin >> array[i];
        }

        unordered_map<long long, long long> frequency;
        for (long long num : array) {
            frequency[num]++;
        }

        vector<pair<long long, long long>> freqVec(frequency.begin(), frequency.end());
        sort(freqVec.begin(), freqVec.end(), [](const pair<long long, long long>& a, const pair<long long, long long>& b) {
            return a.second < b.second;
        });

        long long sum = 0;
        long long removedBlocks = 0;

        for (const auto& pair : freqVec) {
            if (sum + pair.second > k) break;
            sum += pair.second;
            removedBlocks++;
        }

        if (k >= n) {
            cout << 1 << endl;
        } else {
            cout << freqVec.size() - removedBlocks << endl;
        }
    }

    return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long t;
    cin >> t;

    while (t--) {
        long long n, k;
        cin >> n >> k;

        vector<long long> array(n);
        for (long long i = 0; i < n; i++) {
            cin >> array[i];
        }
        unordered_map<long long, long long> frequency;
        for (long long num : array) {
            frequency[num]++;
        }

        if (k >= n) {
            cout << 1 << endl;
            continue;
        }

        priority_queue<long long, vector<long long>, greater<long long>> minHeap;
        for (const auto& pair : frequency) {
            minHeap.push(pair.second);
        }

        long long uniqueCount = frequency.size();
        long long sum = 0;
        while (!minHeap.empty() && sum + minHeap.top() <= k) {
            sum += minHeap.top();
            minHeap.pop();
            uniqueCount--;        }

        cout << uniqueCount << endl;
    }

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

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long t;
    cin >> t;

    while (t--) {
        long long n, k;
        cin >> n >> k;

        vector<long long> array(n);
        for (long long i = 0; i < n; i++) {
            cin >> array[i];
        }

        unordered_map<long long, long long> frequency;
        for (long long num : array) {
            frequency[num]++;
        }

        if (k >= n) {
            cout << 1 << '\n';
            continue;
        }

        vector<long long> freqBucket(n + 1, 0);
        for (const auto& pair : frequency) {
            freqBucket[pair.second]++;
        }

        long long uniqueCount = frequency.size();
        long long sum = 0;

        for (long long i = 1; i <= n; i++) {
            if (freqBucket[i] == 0) continue;

            if (sum + i * freqBucket[i] <= k) {
                sum += i * freqBucket[i];
                uniqueCount -= freqBucket[i];
            } else {
                long long usable = (k - sum) / i;
                uniqueCount -= usable;
                break;
            }
        }

        cout << uniqueCount << '\n';
    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    while (t--) {
        int n, k, temp;
        cin >> n >> k;

        map<int, int> m;
        for (int i = 0; i < n; i++) {
            cin >> temp;
            m[temp]++;
        }

        vector<int> v;
        for (auto x : m) {
            v.push_back(x.second);
        }

        sort(v.begin(), v.end());
        int ans = v.size();

        if (k == 0) {
            cout << ans << endl;
            continue;
        }

        for (int i = 0; i < v.size(); i++) {
            k -= v[i];
            if (k < 0) {
                break;
            }
            ans--;
        }
        cout << max(ans, 1) << endl;
    }

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

Previous submission (verdict: Time limit exceeded on test 14):
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long t;
    cin >> t;

    while (t--) {
        long long n, k;
        cin >> n >> k;

        vector<long long> array(n);
        for (long long i = 0; i < n; i++) {
            cin >> array[i];
        }
        unordered_map<long long, long long> frequency;
        for (long long num : array) {
            frequency[num]++;
        }

        if (k >= n) {
            cout << 1 << endl;
            continue;
        }

        priority_queue<long long, vector<long long>, greater<long long>> minHeap;
        for (const auto& pair : frequency) {
            minHeap.push(pair.second);
        }

        long long uniqueCount = frequency.size();
        long long sum = 0;
        while (!minHeap.empty() && sum + minHeap.top() <= k) {
            sum += minHeap.top();
            minHeap.pop();
            uniqueCount--;        }

        cout << uniqueCount << endl;
    }

    return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long t;
    cin >> t;

    while (t--) {
        long long n, k;
        cin >> n >> k;

        vector<long long> array(n);
        for (long long i = 0; i < n; i++) {
            cin >> array[i];
        }

        unordered_map<long long, long long> frequency;
        for (long long num : array) {
            frequency[num]++;
        }

        if (k >= n) {
            cout << 1 << '\n';
            continue;
        }

        vector<long long> freqBucket(n + 1, 0);
        for (const auto& pair : frequency) {
            freqBucket[pair.second]++;
        }

        long long uniqueCount = frequency.size();
        long long sum = 0;

        for (long long i = 1; i <= n; i++) {
            if (freqBucket[i] == 0) continue;

            if (sum + i * freqBucket[i] <= k) {
                sum += i * freqBucket[i];
                uniqueCount -= freqBucket[i];
            } else {
                long long usable = (k - sum) / i;
                uniqueCount -= usable;
                break;
            }
        }

        cout << uniqueCount << '\n';
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define eb emplace_back

int main()

{

ios::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin >> t;

while(t--)

{

int n;

cin >> n;

vector <int> v;

for(int i=0;i<n;i++)

{

int x;

cin >> x;

v.eb(x);

}

int flag=0;

if(n==2)

{

if(v[0]<=v[1])

{

cout << "YES" <<'\n';

}

else{

cout << "NO" <<'\n';

}

continue;

}

for(int i=2;i<n;i++)

{

if(v[i-1]>v[i] && v[i+1]<v[i])

{

flag=1;

break;

}

}

if(flag==0)

cout << "YES" <<'\n';

else

cout << "NO" <<'\n';

}

return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define eb emplace_back

int main()

{

ios::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin >> t;

while(t--)

{

int n;

cin >> n;

vector <int> v;

for(int i=0;i<n;i++)

{

int x;

cin >> x;

v.eb(x);

}

int flag=0;

if(n==2)

{

if(v[0]<=v[1])

{

cout << "YES" <<'\n';

}

else{

cout << "NO" <<'\n';

}

continue;

}

for(int i=2;i<n-1;i++)

{

if(v[i-1]>v[i] && v[i+1]<v[i])

{

flag=1;

break;

}

}

if(flag==0)

cout << "YES" <<'\n';

else

cout << "NO" <<'\n';

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define eb emplace_back

int main()

{

ios::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin >> t;

while(t--)

{

int n;

cin >> n;

vector <int> v;

for(int i=0;i<n;i++)

{

int x;

cin >> x;

v.eb(x);

}

int flag=0;

if(n==2)

{

if(v[0]<=v[1])

{

cout << "YES" <<'\n';

}

else{

cout << "NO" <<'\n';

}

continue;

}

for(int i=2;i<n-1;i++)

{

if(v[i-1]>v[i] && v[i+1]<v[i])

{

flag=1;

break;

}

}

if(flag==0)

cout << "YES" <<'\n';

else

cout << "NO" <<'\n';

}

return 0;

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define eb emplace_back

int main()

{

ios::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin >> t;

while(t--)

{

int n;

cin >> n;

vector <int> v;

for(int i=0;i<n;i++)

{

int x;

cin >> x;

v.eb(x);

}

int flag=0;

for(int i=0;i<n-1;i++)

{

if(v[i]>v[i+1])

{

flag=1;

break;

}

else if(v[i]<=v[i+1])

{

v[i+1]=v[i+1]-v[i];

v[i]=0;

}

}

if(flag==0)

cout << "YES" <<'\n';

else

cout << "NO" <<'\n';

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define pb push_back

#define eb emplace_back

int main()

{

ios::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin >> t;

while(t--)

{

int n;

cin >> n;

vector <int> v;

for(int i=0;i<n;i++)

{

int x;

cin >> x;

v.eb(x);

}

int flag=0;

if(n==2)

{

if(v[0]<=v[1])

{

cout << "YES" <<'\n';

}

else{

cout << "NO" <<'\n';

}

continue;

}

for(int i=2;i<n;i++)

{

if(v[i-1]>v[i] && v[i+1]<v[i])

{

flag=1;

break;

}

}

if(flag==0)

cout << "YES" <<'\n';

else

cout << "NO" <<'\n';

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n  ;

cin>>n;

vector<ll>v(n) ;

bool is_sorted = false ;



for(int i=0;i<n;i++){

cin>>v[i] ;

}

for(int i=0;i<n-2;i++){

if(v[i]<=v[i+1]){

if(v[i+1]-v[i]<=v[i+2]){

v[i+1]-=v[i] ;

}

}

else{

cout<<"NO"<<endl;

return ;

}

}

cout<<"YES"<<endl;



}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n  ;

cin>>n;

vector<ll>v(n) ;

bool is_sorted = false ;



for(int i=0;i<n;i++){

cin>>v[i] ;

}

if(n==2){

if(v[0]>v[1]){

cout<<"NO"<<endl;

return ;

}

}

for(int i=0;i<n-2;i++){

if(v[i]<=v[i+1]){

if(v[i+1]-v[i]<=v[i+2]){

v[i+1]-=v[i] ;

}

}

else{

cout<<"NO"<<endl;

return ;

}

}

cout<<"YES"<<endl;



}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n  ;

cin>>n;

vector<ll>v(n) ;

bool is_sorted = false ;



for(int i=0;i<n;i++){

cin>>v[i] ;

}

if(n==2){

if(v[0]>v[1]){

cout<<"NO"<<endl;

return ;

}

}

for(int i=0;i<n-2;i++){

if(v[i]<=v[i+1]){

if(v[i+1]-v[i]<=v[i+2]){

v[i+1]-=v[i] ;

}

}

else{

cout<<"NO"<<endl;

return ;

}

}

cout<<"YES"<<endl;



}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n  ;

cin>>n;

vector<ll>v(n) ;

bool is_sorted = false ;



for(int i=0;i<n;i++){

cin>>v[i] ;

}

if(n==2){

if(v[0]>v[1]){

cout<<"NO"<<endl;

return ;

}

}

for(int i=0;i<n-2;i++){

if(v[i]<=v[i+1]){

if((v[i+1]-v[i])<=v[i+2]){

v[i+1]-=v[i] ;

}

else{

cout<<"NO"<<endl;

return ;

}

}

else{

cout<<"NO"<<endl;

return ;

}

}

cout<<"YES"<<endl;



}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n ; cin>>n;

vector<ll>v(n) ;

ll largest = INT_MIN ;

bool formed = true;

for(ll i=0;i<n;i++){

cin>>v[i] ;

largest = max(largest,v[i]) ;

}

debug(largest)

for(ll i=0;i<n;i++){

if(largest == v[i] && i==0){

formed = false ;

break ;



}

}

for(int i=0;i<v.size()-2;i++){

if(v[i+2]<v[i+1]-v[i]){

formed = false ;

break  ;

}

}

if(formed==false){

cout<<"NO"<<endl;

}

else{

cout<<"YES"<<endl;

}





}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n ; cin>>n;

vector<ll>v(n) ;

ll largest = INT_MIN ;

bool formed = true;

for(ll i=0;i<n;i++){

cin>>v[i] ;

largest = max(largest,v[i]) ;

}

debug(largest)

for(ll i=0;i<n;i++){

if(largest == v[i] && i==0){

formed = false ;

break ;



}

}

for(int i=0;i<v.size()-2;i++){

if(v[i+2]<v[i+1]-v[i]){

formed = false ;

break  ;

}

}

if(formed==false){

cout<<"NO"<<endl;

}

else{

cout<<"YES"<<endl;

}





}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " = " << (x) << endl;

#else

#define debug(x)

#endif

using ll = long long ;

void solve(){

ll n  ;

cin>>n;

vector<ll>v(n) ;

bool is_sorted = false ;



for(int i=0;i<n;i++){

cin>>v[i] ;

}

for(int i=0;i<n-2;i++){

if(v[i]<=v[i+1]){

if(v[i+1]-v[i]<=v[i+2]){

v[i+1]-=v[i] ;

}

}

else{

cout<<"NO"<<endl;

return ;

}

}

cout<<"YES"<<endl;



}

int main(){

ios::sync_with_stdio(false);

cin.tie(0);

cout.tie(0) ;

int t;

cin>>t;

while(t--){

solve() ;

}

}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
// Created by Rishi Sharma (@rishisharmapro) on 08-02-2025 at 13:32
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

void solve() {
    int n, maxComponents = 0;
    cin >> n;

    map<int , vector<int>> adjList;
    map<int, int> inDegree;
    int maxInDegree = 0;
    for(int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;
        adjList[u].pb(v);
        adjList[v].pb(u);
        inDegree[u]++;
        inDegree[v]++;
        maxInDegree = max(maxInDegree, max(inDegree[u], inDegree[v]));
    }

    if(n ==  2) {
        cout << 0 << endl;
        return;
    }
    
    // calculating the nodes with maximum in degree
    set<int> nodes;
    for(auto i:inDegree) {
        if(i.second == maxInDegree) {
            nodes.insert(i.first);
        }
    }
    map<int, int> inDegreeAdjacent;
    // now finding the nodes with maximum in degree but there adjacent having minimum in degree
    for(auto i:nodes) {
        int degree = 0;
        for(auto j:adjList[i]) {
            degree += inDegree[j];
        }
        inDegreeAdjacent[degree] = i;
    }

    int maxIndegreeNode = 0;
    maxIndegreeNode = inDegreeAdjacent.begin()->second;
    maxComponents = inDegree[maxIndegreeNode];
    // removing the node with maximum in degree from inDegree
    for(auto i:adjList[maxIndegreeNode]) {
        inDegree[i]--;
    }
    inDegree.erase(maxIndegreeNode);
    // cout << endl << maxIndegreeNode << " " << maxComponents << endl;
    if(sz(nodes) > 1) {
        maxComponents += (inDegreeAdjacent.begin()++)->first;
        cout << maxComponents << endl;
        return;
    }
    
    int ans = maxComponents;
    maxInDegree = 0;
    int node = maxIndegreeNode;
    maxIndegreeNode = 0;
    for(auto i:inDegree) {
        if(i.second > maxInDegree) {
            maxInDegree = i.second;
            maxIndegreeNode = i.first;
        }
    }
    // the node is directly connected to the removed node
    if(find(all(adjList[node]), maxIndegreeNode) != adjList[node].end()) {
        if(maxInDegree > 1) {
            ans += maxInDegree - 2;
        }
        else {
            ans += maxInDegree - 1;
        }
        auto it = find(all(adjList[node]), maxIndegreeNode);
        // cout << maxIndegreeNode << " " << maxInDegree << " " << *it << endl;
    }
    // the node is not directly connected to the removed node
    else {
        ans += maxInDegree - 1;
    }

    cout << ans << endl;
}

int main() {
    // problem: https://codeforces.com/contest/2063/problem/C
    fast_io;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
constexpr int mod=(int)2*1e5+7;
bool ct=false;

inline void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    unordered_map<int,int>m;
    vector<int>s;
    for(auto it:v){
      cin>>it;
      m[it]++;
    }
    for(auto it:m){
      s.push_back(it.second);
    }
    sort(s.begin(),s.end());
    int ans=k;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]<=ans) ans-=s[i],c++;
        else break;
    }
    if((s.size()-c)==0) cout<<1<<"\n";
    else cout<<s.size()-c<<"\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;    
     cin>>t;
    while(t--) solve();
    return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \> 
  你好,                                                   
  操你 母狗!!
*/
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
constexpr int mod=(int)2*1e5+7;
bool ct=false;

inline void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    unordered_map<int,int>m;
    vector<int>s;
    for(auto it:v){
      cin>>it;
      m[it]++;
    }
    for(auto it:m){
      s.push_back(it.second);
    }
    sort(s.begin(),s.end());
    int ans=k;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]<=ans) ans-=s[i],c++;
        else break;
    }
    cout<<max(1,(int)s.size()-c)<<"\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;    
     cin>>t;
    while(t--) solve();
    return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \> 
  你好,                                                   
  操你 母狗!!
*/


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
int solve(){
    int n,k,temp;
    cin>>n>>k;
    map<int, int> m;
 
    for(int i=0;i<n;i++){
        cin>>temp;
        m[temp]++;
    }
    vector<int> v;
    for(auto x:m){
        v.push_back(x.second);
    }
    sort(v.begin(),v.end());
    int ans=v.size();
    // cout<<"ans "<<ans<<endl;
 
    if(k==0){
        cout<<ans<<endl;
        return 0;
    }
 
    for(int i=0;i<v.size();i++){
        k-=v[i];
        if(k<0){
            break;
        }
        ans--;
    }
    cout<<max(ans,1)<<endl;
    return 0;
}
int main()
{
    int testCase=1;
    cin>>testCase;
    while(testCase--){
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
constexpr int mod=(int)2*1e5+7;
bool ct=false;

inline void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    unordered_map<int,int>m;
    vector<int>s;
    for(auto it:v){
      cin>>it;
      m[it]++;
    }
    for(auto it:m){
      s.push_back(it.second);
    }
    sort(s.begin(),s.end());
    int ans=k;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]<=ans) ans-=s[i],c++;
        else break;
    }
    if((s.size()-c)==0) cout<<1<<"\n";
    else cout<<s.size()-c<<"\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;    
     cin>>t;
    while(t--) solve();
    return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \> 
  你好,                                                   
  操你 母狗!!
*/


Submission (verdict: Time limit exceeded on test 14):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
constexpr int mod=(int)2*1e5+7;
bool ct=false;

inline void solve(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    unordered_map<int,int>m;
    vector<int>s;
    for(auto it:v){
      cin>>it;
      m[it]++;
    }
    for(auto it:m){
      s.push_back(it.second);
    }
    sort(s.begin(),s.end());
    int ans=k;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]<=ans) ans-=s[i],c++;
        else break;
    }
    cout<<max(1,(int)s.size()-c)<<"\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t=1;    
     cin>>t;
    while(t--) solve();
    return 0;
}
/*   /\_/\
*   (= ._.)
*   / >  \> 
  你好,                                                   
  操你 母狗!!
*/