ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=200001;
ll n,m;
ll aa[1005][1005];
ll xx[1005];
ll yy[1005];

ll dp(ll x,ll y,string a,string b,string c){
    if(aa[x][y]!=-1) return aa[x][y];
    if(x>=n){
        return yy[y];
    }
    else if(y>=m){
        return xx[x];
    }
    ll ans=1e12;
    if(c[x+y]==a[x]) ans=min(ans,dp(x+1,y,a,b,c));
    else ans=min(ans,1+dp(x+1,y,a,b,c));
    if(c[x+y]==b[y]) ans=min(ans,dp(x,y+1,a,b,c));
    else ans=min(ans,1+dp(x,y+1,a,b,c));
    return aa[x][y]=ans;
}
 
int main(){
    ll T;
    cin>>T;
    while(T--){
        string a,b,c;
        cin>>a;
        cin>>b;
        cin>>c;
        n=a.size();
        m=b.size();
        xx[n-1]=0;
        if(a[n-1]!=c[m+n-1]) xx[n-1]++;
        for(int i=n-2;i>=0;i--){
            xx[i]=xx[i+1];
            if(a[i]!=c[m+i]) xx[i]++;
        }
        yy[m-1]=0;
        if(b[m-1]!=c[n+m-1]) yy[m-1]++;
        for(int i=m-2;i>=0;i--){
            yy[i]=yy[i+1];
            if(b[i]!=c[n+i]) yy[i]++;
        }
        memset(aa,-1,sizeof(aa));
        ll ans=dp(0,0,a,b,c);
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=200001;
ll n,m;
ll xx[1005];
ll yy[1005];

ll dp(ll x,ll y,string a,string b,string c,vector<vector<int>> &aa){
    if(aa[x][y]!=-1) return aa[x][y];
    if(x>=n){
        return yy[y];
    }
    else if(y>=m){
        return xx[x];
    }
    ll ans=1e12;
    if(c[x+y]==a[x]) ans=min(ans,dp(x+1,y,a,b,c,aa));
    else ans=min(ans,1+dp(x+1,y,a,b,c,aa));
    if(c[x+y]==b[y]) ans=min(ans,dp(x,y+1,a,b,c,aa));
    else ans=min(ans,1+dp(x,y+1,a,b,c,aa));
    return aa[x][y]=ans;
}
 
int main(){
    ll T;
    cin>>T;
    while(T--){
        string a,b,c;
        cin>>a;
        cin>>b;
        cin>>c;
        n=a.size();
        m=b.size();
        xx[n-1]=0;
        if(a[n-1]!=c[m+n-1]) xx[n-1]++;
        for(int i=n-2;i>=0;i--){
            xx[i]=xx[i+1];
            if(a[i]!=c[m+i]) xx[i]++;
        }
        yy[m-1]=0;
        if(b[m-1]!=c[n+m-1]) yy[m-1]++;
        for(int i=m-2;i>=0;i--){
            yy[i]=yy[i+1];
            if(b[i]!=c[n+i]) yy[i]++;
        }
        vector<vector<int>> aa(n+5,vector<int> (m+5,-1));
        ll ans=dp(0,0,a,b,c,aa);
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=200001;
ll n,m;
ll aa[1005][1005];
ll xx[1005];
ll yy[1005];

ll dp(ll x,ll y,string a,string b,string c){
    if(aa[x][y]!=-1) return aa[x][y];
    if(x>=n){
        return yy[y];
    }
    else if(y>=m){
        return xx[x];
    }
    ll ans=1e12;
    if(c[x+y]==a[x]) ans=min(ans,dp(x+1,y,a,b,c));
    else ans=min(ans,1+dp(x+1,y,a,b,c));
    if(c[x+y]==b[y]) ans=min(ans,dp(x,y+1,a,b,c));
    else ans=min(ans,1+dp(x,y+1,a,b,c));
    return aa[x][y]=ans;
}
 
int main(){
    ll T;
    cin>>T;
    while(T--){
        string a,b,c;
        cin>>a;
        cin>>b;
        cin>>c;
        n=a.size();
        m=b.size();
        xx[n-1]=0;
        if(a[n-1]!=c[m+n-1]) xx[n-1]++;
        for(int i=n-2;i>=0;i--){
            xx[i]=xx[i+1];
            if(a[i]!=c[m+i]) xx[i]++;
        }
        yy[m-1]=0;
        if(b[m-1]!=c[n+m-1]) yy[m-1]++;
        for(int i=m-2;i>=0;i--){
            yy[i]=yy[i+1];
            if(b[i]!=c[n+i]) yy[i]++;
        }
        memset(aa,-1,sizeof(aa));
        ll ans=dp(0,0,a,b,c);
        cout<<ans<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 16):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=200001;
ll n,m;
ll xx[1005];
ll yy[1005];

ll dp(ll x,ll y,string a,string b,string c,vector<vector<int>> &aa){
    if(aa[x][y]!=-1) return aa[x][y];
    if(x>=n){
        return yy[y];
    }
    else if(y>=m){
        return xx[x];
    }
    ll ans=1e12;
    if(c[x+y]==a[x]) ans=min(ans,dp(x+1,y,a,b,c,aa));
    else ans=min(ans,1+dp(x+1,y,a,b,c,aa));
    if(c[x+y]==b[y]) ans=min(ans,dp(x,y+1,a,b,c,aa));
    else ans=min(ans,1+dp(x,y+1,a,b,c,aa));
    return aa[x][y]=ans;
}
 
int main(){
    ll T;
    cin>>T;
    while(T--){
        string a,b,c;
        cin>>a;
        cin>>b;
        cin>>c;
        n=a.size();
        m=b.size();
        xx[n-1]=0;
        if(a[n-1]!=c[m+n-1]) xx[n-1]++;
        for(int i=n-2;i>=0;i--){
            xx[i]=xx[i+1];
            if(a[i]!=c[m+i]) xx[i]++;
        }
        yy[m-1]=0;
        if(b[m-1]!=c[n+m-1]) yy[m-1]++;
        for(int i=m-2;i>=0;i--){
            yy[i]=yy[i+1];
            if(b[i]!=c[n+i]) yy[i]++;
        }
        vector<vector<int>> aa(n+5,vector<int> (m+5,-1));
        ll ans=dp(0,0,a,b,c,aa);
        cout<<ans<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <algorithm>

static const int inf = 1e9;

void solve() {
    std::string a, b, res;
    std::cin >> a >> b >> res;
    int n = (int) a.size(), m = (int) b.size();
    int dp[n + 1][m + 1];
    std::fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != res[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != res[j]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = std::min(dp[i - 1][j] + (a[i - 1] != res[i + j - 1]),
                                dp[i][j - 1] + (b[j - 1] != res[i + j - 1]));
        }
    }
    std::cout << dp[n][m] << std::endl;
}

int main() {
    int tests;
    std::cin >> tests;
    while (tests--) {
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;

void dfs(int node , int par , vii &adj , int &mx ){
    int s = adj[node].size();
    int l = adj[mx].size();
    if( s > l) mx = node;
    // cout<<mx<<" ";

    for(auto &x : adj[node]){
        if(x == par) continue;
        dfs(x,node,adj,mx);
    } 
}

void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vii adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int node = 1;

    for(int i = 1;i<=n;i++){
        if(deg[i] == 1) node = i;
    }

    int mx = node;

    dfs(node,0,adj,mx);
    // cout<<mx<<" ";
    int ans = deg[mx];
    deg[mx] = 0;

    for(auto &x : adj[mx]){
        deg[x]--;
    }
    deg[mx] = 0;
    for(int i = 1;i<=n;i++){
        if(deg[i] > deg[mx]) mx = i;
    }

    ans += (deg[mx] - 1);

    cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;


void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vector<set<int>> adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].insert(y);
        adj[y].insert(x);
    }

    int mx = 0;

    for(auto & x : deg){
        mx = max(mx,x);
    }
    vector<int> ns;
    for(int i = 1;i<=n;i++){
        if(deg[i] == mx){
            ns.pb(i);
        }
    }

    if(ns.size() == 1){
        for(auto & x : adj[ns[0]]){
            deg[x]--;
        }
        int sec = 0;
        for(int i = 1;i<=n;i++){
            if(deg[i] > sec && deg[i] < mx){
                sec = deg[i];
            }
        }

        cout<<mx+sec-1<<endl;
        return;
    }
    if(ns.size() == 2){
        if(adj[ns[0]].find(ns[1]) != adj[ns[0]].end()){
            cout<<(mx)+(mx-2)<<endl;
            return;
        }
    }
    // cout<<mx<<" ";
    cout<<2*(mx) -1<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;

void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vector<vector<int>> adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans = 1;
    for(int i = 0 ;i<2;i++){
        int mx = 0;
        for(int j = 1 ;j<n+1;j++){
            if(deg[j] > mx){
                mx = j;
            }
        }
        ans += (deg[mx] - 1);
        deg[mx] = 0;
        for(auto &x : adj[mx]) deg[x]--;
    }
    ans = max(ans ,0ll);
    cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;

void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vector<vector<int>> adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans = 1;
    for(int i = 0 ;i<2;i++){
        int mx = 0;
        for(int j = 1 ;j<n+1;j++){
            if(deg[j] > deg[mx]){
                mx = j;
            }
        }
        ans += (deg[mx] - 1);
        deg[mx] = 0;
        for(auto &x : adj[mx]) deg[x]--;
    }
    ans = max(ans ,0ll);
    cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;

void dfs(int node , int par , vii &adj , int &mx ){
    int s = adj[node].size();
    int l = adj[mx].size();
    if( s > l) mx = node;
    // cout<<mx<<" ";

    for(auto &x : adj[node]){
        if(x == par) continue;
        dfs(x,node,adj,mx);
    } 
}

void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vii adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int node = 1;

    for(int i = 1;i<=n;i++){
        if(deg[i] == 1) node = i;
    }

    int mx = node;

    dfs(node,0,adj,mx);
    // cout<<mx<<" ";
    int ans = deg[mx];
    deg[mx] = 0;

    for(auto &x : adj[mx]){
        deg[x]--;
    }
    deg[mx] = 0;
    for(int i = 1;i<=n;i++){
        if(deg[i] > deg[mx]) mx = i;
    }

    ans += (deg[mx] - 1);

    cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;

void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vector<vector<int>> adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans = 1;
    for(int i = 0 ;i<2;i++){
        int mx = 0;
        for(int j = 1 ;j<n+1;j++){
            if(deg[j] > mx){
                mx = j;
            }
        }
        ans += (deg[mx] - 1);
        deg[mx] = 0;
        for(auto &x : adj[mx]) deg[x]--;
    }
    ans = max(ans ,0ll);
    cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define fi(a) for(auto &x : a) cin >> x;
#define pb push_back
#define pp pop_back

int mod = 1e9 + 7;

void solve(){
    int n;
    cin>>n;
    vi deg(n+1,0);
    vector<vector<int>> adj(n+1);
    for(int i = 0 ;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        deg[x]++;
        deg[y]++;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int ans = 1;
    for(int i = 0 ;i<2;i++){
        int mx = 0;
        for(int j = 1 ;j<n+1;j++){
            if(deg[j] > deg[mx]){
                mx = j;
            }
        }
        ans += (deg[mx] - 1);
        deg[mx] = 0;
        for(auto &x : adj[mx]) deg[x]--;
    }
    ans = max(ans ,0ll);
    cout<<ans<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    cin >> T;

    int mod = 1e9 + 7;
    while(T--){
        solve();
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

const int N = 2e5 + 10;

char s[N];

int n;



void solve(){

scanf("%s", s + 1);

n = strlen(s + 1);

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

int v = s[i] - '0';

if(v >= 8)continue;  // 9 or 8

else{

for(int tar = 8; tar > v; tar -- ){

// printf("%d %d\n", i, tar);

int flag = 0;

for(int j = 1; j <= n; j ++ ){

int need = tar + j;

if(need == 10)break;

if(need == s[i + j] - '0'){

flag = 1;



for(int k = j; k >= 1; k -- ){

s[i + k] = s[i + k - 1];

}



s[i] = tar + '0';

break;

}

}

if(flag)break;

}

}

// printf("%s\n", s + 1);

}

printf("%s\n", s + 1);

}



int main()

{

int T;

scanf("%d", &T);

while(T -- ){

solve();

}

return 0;

}

Submission (verdict: Accepted):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

const int N = 2e5 + 10;

char s[N];

int n;



void solve(){

scanf("%s", s + 1);

n = strlen(s + 1);

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

int v = s[i] - '0';

if(v >= 8)continue;  // 9 or 8

else{

for(int tar = 8; tar > v; tar -- ){

// printf("%d %d\n", i, tar);

int flag = 0;

for(int j = 1; i + j <= n; j ++ ){

int need = tar + j;

if(need == 10)break;

if(need == s[i + j] - '0'){

flag = 1;



for(int k = j; k >= 1; k -- ){

s[i + k] = s[i + k - 1];

}



s[i] = tar + '0';

break;

}

}

if(flag)break;

}

}

// printf("%s\n", s + 1);

}

printf("%s\n", s + 1);

}



int main()

{

int T;

scanf("%d", &T);

while(T -- ){

solve();

}

return 0;

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


Submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

const int N = 1e5 + 10;

char s[N];

int n;



void solve(){

scanf("%s", s + 1);

n = strlen(s + 1);

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

int v = s[i] - '0';

if(v >= 8)continue;  // 9 or 8

else{

for(int tar = 8; tar > v; tar -- ){

// printf("%d %d\n", i, tar);

int flag = 0;

for(int j = 1; j <= n; j ++ ){

int need = tar + j;

if(need == 10)break;

if(need == s[i + j] - '0'){

flag = 1;



for(int k = j; k >= 1; k -- ){

s[i + k] = s[i + k - 1];

}



s[i] = tar + '0';

break;

}

}

if(flag)break;

}

}

// printf("%s\n", s + 1);

}

printf("%s\n", s + 1);

}



int main()

{

int T;

scanf("%d", &T);

while(T -- ){

solve();

}

return 0;

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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

const int N = 1e5 + 10;

char s[N];

int n;



void solve(){

scanf("%s", s + 1);

n = strlen(s + 1);

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

int v = s[i] - '0';

if(v >= 8)continue;  // 9 or 8

else{

for(int tar = 8; tar > v; tar -- ){

// printf("%d %d\n", i, tar);

int flag = 0;

for(int j = 1; j <= n; j ++ ){

int need = tar + j;

if(need == 10)break;

if(need == s[i + j] - '0'){

flag = 1;



for(int k = j; k >= 1; k -- ){

s[i + k] = s[i + k - 1];

}



s[i] = tar + '0';

break;

}

}

if(flag)break;

}

}

// printf("%s\n", s + 1);

}

printf("%s\n", s + 1);

}



int main()

{

int T;

scanf("%d", &T);

while(T -- ){

solve();

}

return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <algorithm>

#include <cstring>



using namespace std;

const int N = 2e5 + 10;

char s[N];

int n;



void solve(){

scanf("%s", s + 1);

n = strlen(s + 1);

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

int v = s[i] - '0';

if(v >= 8)continue;  // 9 or 8

else{

for(int tar = 8; tar > v; tar -- ){

// printf("%d %d\n", i, tar);

int flag = 0;

for(int j = 1; j <= n; j ++ ){

int need = tar + j;

if(need == 10)break;

if(need == s[i + j] - '0'){

flag = 1;



for(int k = j; k >= 1; k -- ){

s[i + k] = s[i + k - 1];

}



s[i] = tar + '0';

break;

}

}

if(flag)break;

}

}

// printf("%s\n", s + 1);

}

printf("%s\n", s + 1);

}



int main()

{

int T;

scanf("%d", &T);

while(T -- ){

solve();

}

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;
// #define int long long

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 1) << endl;
    }
    return 0;
}

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

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 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 2):
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() <= k) {
                k -= v.back();
                v.pop_back();
            }
        }
        cout <<  max((int)v.size(), 1LL) << endl;
    }
    return 0;
}

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

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 1LL) << endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


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

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0) {
            if(v.back() <= k) {
                k -= v.back();
                v.pop_back();
            }
        }
        cout <<  max((int)v.size(), 1LL) << 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;
#define int long long

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 1LL) << endl;
    }
    return 0;
}

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

int32_t main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        unordered_map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 1) << endl;
    }
    return 0;
}