ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

// Fast I/O
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// Input/Output file setup for debugging
#ifndef ONLINE_JUDGE
    #define FILE_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);freopen("error.txt", "w", stderr)
#else
    #define FILE_IO
#endif

// Type Definitions
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define vii vector<int>
#define vll vector<ll>
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// Constants
const ll MOD = 1e9 + 7;     // Modular arithmetic constant

// Debugging Macro (Prints variable values during local testing)
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << " = " << x << endl
    #define debugv(v) cerr << #v << " = "; for (auto i : v) cerr << i << " "; cerr << endl
#else
    #define debug(x)
    #define debugv(x)
#endif

// Utility Functions
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }

// Main problem-solving function
void solve() {
    int n;
    cin >> n;
    vii v(n), k;
    for(auto &a: v) cin >> a;
    ll ans = accumulate(all(v),0LL);
    while(n > 0){
        for(int i = 0; i < n-1; ++i){
            k.pb(v[i+1] - v[i]);
        }
        ans = max(ans, abs(accumulate(all(k),0LL)));
        for(int i = 0; i < n-1; ++i){
            v[i] = k[i];
        }
        k.clear();
        n--;
    }
    cout << ans << endl;

}

int main() {
    // File and Fast I/O Setup
    FAST_IO;
    FILE_IO;

    // Number of test cases
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


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

// Fast I/O
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

// Input/Output file setup for debugging
#ifndef ONLINE_JUDGE
    #define FILE_IO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);freopen("error.txt", "w", stderr)
#else
    #define FILE_IO
#endif

// Type Definitions
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define vii vector<int>
#define vll vector<ll>
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// Constants
const ll MOD = 1e9 + 7;     // Modular arithmetic constant

// Debugging Macro (Prints variable values during local testing)
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << " = " << x << endl
    #define debugv(v) cerr << #v << " = "; for (auto i : v) cerr << i << " "; cerr << endl
#else
    #define debug(x)
    #define debugv(x)
#endif

// Utility Functions
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll modAdd(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
ll modSub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
ll modMul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }


void dfs(int vertex, vii graph[], int visited[]){
    if(visited[vertex]) return;
    visited[vertex] = 1;
    for(auto &child: graph[vertex]){
        dfs(child,graph,visited);
    }
}

// Main problem-solving function
void solve() {
    int n;
    cin >> n;
    vii v[n+1];
    vector<pair<int,int>> cnt;
    for(int i = 0; i <= n; ++i){
        cnt.pb({0,i});
    }

    int visited[n+1];
    memset(visited,0,sizeof(visited));
    for(int i = 0; i < n-1; ++i){
        int u,x;
        cin >> u >> x;
        v[u].pb(x);
        cnt[u].first++;
        
    }
    sort(all(cnt),greater<pair<int,int>>());
    visited[cnt[0].second] = 1;
    visited[cnt[1].second] = 1;
    int sum = 0;
    for(int i = 1; i <= n; ++i){
        if(visited[i]) continue;
        else{
            dfs(i,v,visited);
            sum++;
        }
    }
    cout << sum << endl;


}

int main() {
    // File and Fast I/O Setup
    FAST_IO;
    FILE_IO;

    // Number of test cases
    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int u=0;u<=20;u++)
        for(int i=n-2;i>=0;i--){
            if((int)s[i+1]-1>(int)s[i]){
                swap(s[i],s[i+1]) ;
                s[i]-- ;
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int u=0;u<=20;u++)
        for(int i=n-2;i>=0;i--){
            if((int)s[i+1]-1>(int)s[i]){
                swap(s[i],s[i+1]) ;
                s[i]-- ;
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int i=n-1;i>=0;i--){
            for(int j=i-1;j>=0&&j>=i-10;j--){
                if((int)s[j]<(int)s[j+1]-1){
                    swap(s[j],s[j+1]) ;
                    s[j]-- ;
                }
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int u=0;u<=1000;u++)
        for(int i=n-2;i>=0;i--){
            if((int)s[i+1]-1>(int)s[i]){
                swap(s[i],s[i+1]) ;
                s[i]-- ;
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int u=0;u<=1000;u++){
            if(u%2){
                for(int i=n-2;i>=0;i--){
                    if((int)s[i+1]-1>(int)s[i]){
                        swap(s[i],s[i+1]) ;
                        s[i]-- ;
                    }
                }
            }
            else {
                for(int i=0;i<=n-2;i++){
                    if((int)s[i+1]-1>(int)s[i]){
                        swap(s[i],s[i+1]) ;
                        s[i]-- ;
                    }
                }   
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int i=n-1;i>=0;i--){
            for(int j=i-1;j>=0&&j>=i-10;j--){
                if((int)s[j]<(int)s[j+1]-1){
                    swap(s[j],s[j+1]) ;
                    s[j]-- ;
                }
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
    #endif
    int tt ;
    cin >> tt ;
    while(tt--){
        string s ;
        cin >> s ;
        int n=(int)s.size() ;
        for(int u=0;u<=1000;u++)
        for(int i=n-2;i>=0;i--){
            if((int)s[i+1]-1>(int)s[i]){
                swap(s[i],s[i+1]) ;
                s[i]-- ;
            }
        }
        cout << s << '\n' ;
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define print(vec) for(auto &x : vec) {cout << x << ' ';} cout << endl;
const ll mod = 998244353;
using namespace std;

// Function to calculate XOR sum
ll so(ll a, ll b, ll c) {
    return (a ^ b) + (a ^ c) + (b ^ c);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll t;
    cin >> t;
    
    while (t--) {
        ll n, m;
        cin >> n >> m;

        ll bestXor = LLONG_MIN;
        vll ans(3);

        ll l = n, r = m;

        while (r - l > 1) {
            ll mid = l + (r - l) / 2;

            ll xorMid = so(n, mid, m);
            if (xorMid > bestXor) {
                bestXor = xorMid;
                ans = {n, mid, m};
            }

            if (so(n, mid + 1, m) >= so(n, mid - 1, m)) {
                l = mid;
            } else {
                r = mid;
            }
        }

        print(ans);
    }
    
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define print(vec) for(auto &x : vec) {cout << x << ' ';} cout << endl;
const ll mod = 998244353;
using namespace std;

// Function to calculate XOR sum
ll so(ll a, ll b, ll c) {
    return (a ^ b) + (a ^ c) + (b ^ c);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll t;
    cin >> t;
    
    while (t--) {
        ll n, m;
        cin >> n >> m;

        ll bestXor = LLONG_MIN;
        vll ans(3);

        ll l = n, r = m;

        while (r - l > 1) {
            ll mid = l + (r - l) / 2;

            ll xorMid = so(n, mid, m);
            if (xorMid > bestXor) {
                bestXor = xorMid;
                ans = {n, mid, m};
            }

            if (so(n, mid + 1, m) >= so(n, mid - 1, m)) {
                l = mid;
            } else {
                r = mid;
            }
        }

        print(ans);
    }
    
    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define print(vec) for(auto &x : vec) {cout << x << ' ';} cout << endl;
const ll mod = 998244353;
using namespace std;

// Function to calculate XOR sum
ll so(ll a, ll b, ll c) {
    return (a ^ b) + (a ^ c) + (b ^ c);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll t;
    cin >> t;
    
    while (t--) {
        ll n, m;
        cin >> n >> m;

        ll bestXor = LLONG_MIN;
        vll ans(3);

        ll l = n, r = m;

        while (r - l > 1) {
            ll mid = l + (r - l) / 2;

            ll xorMid = so(n, mid, m);
            if (xorMid > bestXor) {
                bestXor = xorMid;
                ans = {n, mid, m};
            }

            if (so(n, mid + 1, m) >= so(n, mid , m)) {
                l = mid;
            } else if (so(n, mid - 1, m) >= so(n, mid , m)){
                r = mid;
            }
            else{
                break;
            }
        }

        print(ans);
    }
    
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Runtime error on test 16):
#include <stdio.h>
#include <string.h>

#define MIN(x, y) ((x)<=(y)?(x):(y))

const int N = 1e3+5, inf = N*3;

int dp[N][N];

int solver(const char* a, const char* b, const char* c){
    int n = strlen(a), m = strlen(b), k = strlen(c);
    for(int i=0; i<=k; ++i)
        for(int j=0; j<=n; ++j)
            dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=1; i<=k; ++i){
        for(int j=0; j<=MIN(i,n); ++j){
            if(i-j>m) continue;
            int val1 = (i-j-1>=0) ? (dp[i-1][j]+(b[i-j-1]!=c[i-1])) : inf;
            int val2 = (j-1>=0) ? dp[i-1][j-1]+(a[j-1]!=c[i-1]) : inf;
            dp[i][j] = MIN(val1, val2);
        }
    }
    return dp[k][n];
}

int main(void){
    int T;
    char a[N], b[N], c[N];
    scanf("%d", &T);
    while(T--){
        scanf("%s%s%s", a, b, c);
        printf("%d\n", solver(a, b, c));
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 16):
#include <stdio.h>
#include <string.h>

#define MIN(x, y) ((x)<=(y)?(x):(y))

const int N = 1e3+5, inf = N*3;

int dp[N][N];

int solver(const char* a, const char* b, const char* c){
    int n = strlen(a), m = strlen(b), k = strlen(c);
    for(int i=0; i<=k; ++i)
        for(int j=0; j<=n; ++j)
            dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=1; i<=k; ++i){
        for(int j=0; j<=MIN(i,n); ++j){
            if(i-j>m) continue;
            int val1 = (i-j-1>=0) ? (dp[i-1][j]+(b[i-j-1]!=c[i-1])) : inf;
            int val2 = (j-1>=0) ? dp[i-1][j-1]+(a[j-1]!=c[i-1]) : inf;
            dp[i][j] = MIN(val1, val2);
        }
    }
    return dp[k][n];
}

int main(void){
    int T;
    char a[N], b[N], c[N];
    scanf("%d", &T);
    while(T--){
        scanf("%s%s%s", a, b, c);
        printf("%d\n", solver(a, b, c));
    }
    return 0;
}

Submission (verdict: Runtime error on test 16):
#include <stdio.h>
#include <string.h>

#define MIN(x, y) ((x)<=(y)?(x):(y))

const int N = 1e3+5, inf = N*3;

int dp[N][N];

int solver(const char* a, const char* b, const char* c){
    int n = strlen(a), m = strlen(b), k = strlen(c);
    for(int i=0; i<=k; ++i)
        for(int j=0; j<=n; ++j)
            dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=1; i<=k; ++i){
        for(int j=0; j<=MIN(i,n); ++j){
            if(i-j>m) continue;
            int val1 = (i-j-1>=0) ? (dp[i-1][j]+(b[i-j-1]!=c[i-1])) : inf;
            int val2 = (j-1>=0) ? dp[i-1][j-1]+(a[j-1]!=c[i-1]) : inf;
            dp[i][j] = MIN(val1, val2);
        }
    }
    return dp[k][n];
}

int main(void){
    int T;
    char a[N], b[N], c[2*N];
    scanf("%d", &T);
    while(T--){
        scanf("%s%s%s", a, b, c);
        printf("%d\n", solver(a, b, c));
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Runtime error on test 16):
#include <stdio.h>
#include <string.h>

#define MIN(x, y) ((x)<=(y)?(x):(y))

const int N = 1e3+5, inf = N*3;

int dp[N][N];

int solver(const char* a, const char* b, const char* c){
    int n = strlen(a), m = strlen(b), k = strlen(c);
    for(int i=0; i<=k; ++i)
        for(int j=0; j<=n; ++j)
            dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=1; i<=k; ++i){
        for(int j=0; j<=MIN(i,n); ++j){
            if(i-j>m) continue;
            int val1 = (i-j-1>=0) ? (dp[i-1][j]+(b[i-j-1]!=c[i-1])) : inf;
            int val2 = (j-1>=0) ? dp[i-1][j-1]+(a[j-1]!=c[i-1]) : inf;
            dp[i][j] = MIN(val1, val2);
        }
    }
    return dp[k][n];
}

int main(void){
    int T;
    char a[N], b[N], c[2*N];
    scanf("%d", &T);
    while(T--){
        scanf("%s%s%s", a, b, c);
        printf("%d\n", solver(a, b, c));
    }
    return 0;
}

Submission (verdict: Accepted):
#include <stdio.h>
#include <string.h>

#define MIN(x, y) ((x)<=(y)?(x):(y))

const int N = 1e3+5, inf = N*3;

int dp[2*N][N];

int solver(const char* a, const char* b, const char* c){
    int n = strlen(a), m = strlen(b), k = strlen(c);
    for(int i=0; i<=k; ++i)
        for(int j=0; j<=n; ++j)
            dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=1; i<=k; ++i){
        for(int j=0; j<=MIN(i,n); ++j){
            if(i-j>m) continue;
            int val1 = (i-j-1>=0) ? (dp[i-1][j]+(b[i-j-1]!=c[i-1])) : inf;
            int val2 = (j-1>=0) ? dp[i-1][j-1]+(a[j-1]!=c[i-1]) : inf;
            dp[i][j] = MIN(val1, val2);
        }
    }
    return dp[k][n];
}

int main(void){
    int T;
    char a[N], b[N], c[2*N];
    scanf("%d", &T);
    while(T--){
        scanf("%s%s%s", a, b, c);
        printf("%d\n", solver(a, b, c));
    }
    return 0;
}
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>
using namespace std;

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];
        }

        // Count the frequency of each element
        unordered_map<int, int> freq;
        for (int num : a) {
            freq[num]++;
        }

        // Store the frequencies in a min-heap (priority queue)
        priority_queue<int, vector<int>, greater<int>> minHeap;
        for (auto &entry : freq) {
            minHeap.push(entry.second);
        }

        // Reduce the smallest groups using k changes
        while (k > 0 && !minHeap.empty()) {
            int smallest = minHeap.top();
            if (k >= smallest) {
                k -= smallest;
                minHeap.pop();
            } else {
                break;
            }
        }

        if(minHeap.empty())cout<<1<<endl;
        else cout<<minHeap.size()<<endl;
    }
    return 0;
}


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

vector<int> getLengths(vector<int> &arr)
{
    sort(arr.begin(),arr.end());
    vector<int> lengths = {1};

    for(int i=1;i<arr.size();i++){
        if(arr[i]==arr[i-1])lengths.back()++;
        else lengths.emplace_back(1);
    }

    return lengths;
}

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

    while (t--)
    {
        int res=0;
        int a, b;
        cin >> a >> b;
        vector<int> arr(a);

        for (int i = 0; i < a; i++)
        {
            cin >> arr[i];
        }

        vector<int> arr1 = getLengths(arr);

        sort(arr1.begin(), arr1.end());
        
        for(int i=0;i<arr1.size()-1;i++){
            if(arr1[i]>b){
                res = arr1.size()-i;
                break;
            }
            b-=arr1[i];
        }

        (res>0)?cout<<res<<endl:cout<<1<<endl;

    }

    return 0;

}
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>
using namespace std;

vector<int> getLengths(const vector<int> &arr)
{
    unordered_map<int, int> counts;
    for (int num : arr)
    {
        counts[num]++;
    }
    vector<int> lengths;
    for (const auto &pair : counts)
    {
        lengths.push_back(pair.second);
    }
    return lengths;
}

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

    while (t--)
    {
        int a, b;
        cin >> a >> b;
        vector<int> arr(a);

        for (int i = 0; i < a; i++)
        {
            cin >> arr[i];
        }

        vector<int> arr1 = getLengths(arr);

        sort(arr1.begin(), arr1.end());

        int max = arr1[a - 1];

        arr1.pop_back();

        int i=0;

        while(b>0){
            if(arr1.empty())break;
            else{
                if(arr1[0]<=b){
                    b-=arr1[0];
                    arr1.erase(arr1.begin());
                }else break;
            }
         }

         cout<<arr1.size()+1<<endl;

    }

    return 0;

}

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

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];
        }

        // Count the frequency of each element
        unordered_map<int, int> freq;
        for (int num : a) {
            freq[num]++;
        }

        // Store the frequencies in a min-heap (priority queue)
        priority_queue<int, vector<int>, greater<int>> minHeap;
        for (auto &entry : freq) {
            minHeap.push(entry.second);
        }

        // Reduce the smallest groups using k changes
        while (k > 0 && !minHeap.empty()) {
            int smallest = minHeap.top();
            if (k >= smallest) {
                k -= smallest;
                minHeap.pop();
            } else {
                break;
            }
        }

        if(minHeap.empty())cout<<1<<endl;
        else cout<<minHeap.size()<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>
using namespace std;
 
vector<int> getLengths(const vector<int>& arr) { 
    unordered_map<int, int> counts; 
    for (int num : arr) { 
        counts[num]++; 
    } 
    vector<int> lengths; 
    for (const auto& pair : counts) { 
        lengths.push_back(pair.second); 
    }
    return lengths; 
}
 
int res(vector<int>& arr1, int b) {
    int groupsRemoved = 0;
    sort(arr1.begin(), arr1.end()); 
    int uniqueCount = arr1.size(); 
 
    for (int i = 0; i < arr1.size(); i++) {
        if (b >= arr1[i]) { 
            b -= arr1[i];  
            groupsRemoved++; 
        } else {
            break; 
        }
    }
    
    return (groupsRemoved == uniqueCount) ? 1 : uniqueCount - groupsRemoved;
}
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t; 
    cin >> t;
 
    while (t--) {
        int a, b; 
        cin >> a >> b;
        vector<int> arr(a);
 
        for (int i = 0; i < a; i++) {
            cin >> arr[i]; 
        }
 
        vector<int> arr1 = getLengths(arr); 
 
        cout << res(arr1, b) << endl;
    }
 
    return 0;
}