ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

const int N = 1e5 + 10;

typedef long long ll;



void Func() {

    ll n, l, r;

    cin >> n >> l >> r;

    priority_queue<ll, vector<ll>, greater<ll> > q2;

    priority_queue<ll> q1;

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

        ll x;

        cin >> x;

        if (l <= i && i <= r) {

            q1.push(x);

        } else {

            q2.push(x);

        }

    }

    while (!q2.empty() && !q1.empty() && q1.top() > q2.top()) {

        q1.pop();

        q1.push(q2.top());

        q2.pop();

    }

    ll ans = 0;

    while (!q1.empty()) {

        ans += q1.top();

        q1.pop();

    }

    cout << ans << endl;

}



int main() {

    int T;

    cin >> T;

    while (T--) {

        Func();

    }

    return 0;

}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;

void Func() {
    ll n, l, r;
    cin >> n >> l >> r;
    priority_queue<ll, vector<ll>, greater<ll> > q2;
    priority_queue<ll> q1;
    queue<ll> q;
    for (int i = 1; i <= n; i++) {
        ll x;
        cin >> x;
        if (l <= i && i <= r) {
            q1.push(x);
        } else {
            q2.push(x);
        }
    }
    while (!q2.empty() && !q1.empty() && q1.top() > q2.top()) {
        q1.pop();
        q.push(q2.top());
        q2.pop();
    }
    ll ans = 0;
    while (!q1.empty()) {
        ans += q1.top();
        q1.pop();
    }
    while (!q.empty()) {
        ans += q.front();
        q.pop();
    }
    cout << ans << endl;
}

int main() {
#ifdef LOCAL
    freopen("Testlib.in", "r", stdin);
    freopen("Code.out", "w", stdout);
#endif
    int T;
    cin >> T;
    while (T--) {
        Func();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve() {

string s;

cin >> s;

const int n = s.length();

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

for (int j{i}; j && s[j] > '0'; --j) {

if (s[j] > s[j - 1] + 1) {

s[j] -= 1;

swap(s[j], s[j - 1]);

}

}

}

cout << s << '\n';

}



int main() {

cin.tie(0)->sync_with_stdio(0);

int t; cin >> t; while (t--)

solve();

}

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

using namespace std;



void solve() {

string s;

cin >> s;

const int n = s.length();

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

for (int j{i}; j && s[j] > s[j - 1] + 1; --j) {

s[j] -= 1;

swap(s[j], s[j - 1]);

}

}

cout << s << '\n';

}



int main() {

cin.tie(0)->sync_with_stdio(0);

int t; cin >> t; while (t--)

solve();

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



void solve() {

string s;

cin >> s;

const int n = s.length();

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

for (int j{i}; j; --j) {

if (s[j] > s[j - 1] + 1) {

s[j] -= 1;

swap(s[j], s[j - 1]);

}

}

}

cout << s << '\n';

}



int main() {

cin.tie(0)->sync_with_stdio(0);

int t; cin >> t; while (t--)

solve();

}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;



void solve() {

string s;

cin >> s;

const int n = s.length();

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

for (int j{i}; j; --j) {

if (s[j] > s[j - 1] + 1) {

s[j] -= 1;

swap(s[j], s[j - 1]);

}

}

}

cout << s << '\n';

}



int main() {

cin.tie(0)->sync_with_stdio(0);

int t; cin >> t; while (t--)

solve();

}

Submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;



void solve() {

string s;

cin >> s;

const int n = s.length();

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

for (int j{i}; j && s[j] > '0'; --j) {

if (s[j] > s[j - 1] + 1) {

s[j] -= 1;

swap(s[j], s[j - 1]);

}

}

}

cout << s << '\n';

}



int main() {

cin.tie(0)->sync_with_stdio(0);

int t; cin >> t; while (t--)

solve();

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



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  for (auto& ai : a) {

    cin >> ai;

  }

  bool ans{true};

  for (int i{1}; ans && i < n; ++i) {

    ans &= a[i - 1] < a[i];

    const auto mn{min(a[i - 1], a[i])};

    a[i - 1] -= n, a[i] -= mn;

  }

  cout << (ans ? "YES" : "NO") << '\n';

}



int main() {

  int t; cin >> t; while (t--)

    solve();

}



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

using namespace std;



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  for (auto& ai : a) {

    cin >> ai;

  }

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

    const auto mn{min(a[i - 1], a[i])};

    a[i - 1] -= n, a[i] -= mn;

  }

  bool ans{true};

  for (int i{1}; ans && i < n; ++i) {

    ans &= a[i - 1] < a[i];

  }

  cout << (ans ? "YES" : "NO") << '\n';

}



int main() {

  int t; cin >> t; while (t--)

    solve();

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

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

using namespace std;



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  for (auto& ai : a) {

    cin >> ai;

  }

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

    const auto mn{min(a[i - 1], a[i])};

    a[i - 1] -= n, a[i] -= mn;

  }

  bool ans{true};

  for (int i{1}; ans && i < n; ++i) {

    ans &= a[i - 1] < a[i];

  }

  cout << (ans ? "YES" : "NO") << '\n';

}



int main() {

  int t; cin >> t; while (t--)

    solve();

}



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

using namespace std;



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  for (auto& ai : a) {

    cin >> ai;

  }

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

    const auto mn{min(a[i - 1], a[i])};

    a[i - 1] -= mn, a[i] -= mn;

  }

  bool ans{true};

  for (int i{1}; ans && i < n; ++i) {

    ans &= a[i - 1] <= a[i];

  }

  cout << (ans ? "YES" : "NO") << '\n';

}



int main() {

  int t; cin >> t; while (t--)

    solve();

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



void solve() {

  int n;

  cin >> n;

  vector<int> a(n);

  for (auto& ai : a) {

    cin >> ai;

  }

  bool ans{true};

  for (int i{1}; ans && i < n; ++i) {

    ans &= a[i - 1] < a[i];

    const auto mn{min(a[i - 1], a[i])};

    a[i - 1] -= n, a[i] -= mn;

  }

  cout << (ans ? "YES" : "NO") << '\n';

}



int main() {

  int t; cin >> t; while (t--)

    solve();

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


Submission (verdict: Wrong answer on test 2):
/*ॐ देविकानन्दनाय विधमहे वासुदेवाय धीमहि तन्नो कृष्ण:प्रचोदयात
ऊं श्रीं नमः श्रीकृष्णाय परिपूर्णतमाय स्वाहा
ओम क्लीम कृष्णाय नमः
श्री कृष्ण गोविंद हरे मुरारे, हे नाथ नारायण वासुदेवा
गोकुल नाथाय नमः
:निखिलेश गुप्ता*/


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

typedef long long ll;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(a, x) for (auto &a : x)
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vpdd = vector<pdd>;

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    unordered_map<int, int> mp;
    for(int i = 0; i < n; i++){
        mp[arr[i]]++;
    }
    vector<int> freq;
    for(auto &x : mp){
        freq.push_back(x.second);
    }
    sort(begin(freq), end(freq), greater<int>());
    int i = freq.size() - 1;
    while(k > 0 && i >= 0){
        if(k >= freq[i]){
            k -= freq.back();
            freq.pop_back();
        }
        else break;
    }
    cout << (freq.empty() ? 1 : freq.size()) << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int tt;
    cin >> tt;
    while(tt--) {
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: Java 21


Submission (verdict: Wrong answer on test 4):
import java.util.*;

import java.lang.*;

import java.io.*;



public class Codeforces {

    public static void main(String[] args){

        FastReader fr = new FastReader();

        int tc = fr.nextInt();



        while (tc-- > 0) {

            solve(fr);

        }

    }





    private static void solve(FastReader fr) {

        String a = fr.next();

        String b = fr.next();

        String c = fr.next();

        int[][][] dp = new int[a.length()+2][b.length()+2][c.length()+2];



        for(int[][] mat : dp) for(int[] row : mat) Arrays.fill(row, -1);



        System.out.println(solve(a, b, c, 0, 0, 0, dp));

    }



    static int solve(String a, String b, String c, int i, int j, int k, int[][][] dp) {

        if(k == c.length()) return 0;

        if(i > a.length() || j > b.length()) return (int)(1e7);

        boolean isAMatch = false;

        boolean isBMatch = false;



        if(dp[i][j][k] != -1) return dp[i][j][k];



        if(i < a.length() && a.charAt(i) == c.charAt(k)){

            isAMatch = true;

        }else if(j < b.length() && b.charAt(j) == c.charAt(k)){

            isBMatch = true;

        }



        int ans1 = solve(a, b, c, i+1, j, k+1, dp) + (isAMatch ? 0 : 1);

        int ans2 = solve(a, b, c, i, j + 1, k+1, dp) + (isBMatch ? 0 : 1);



        return dp[i][j][k] = Math.min(ans1, ans2);

    }





    static int[] readIntArray(FastReader fr, int n){

        int[] arr = new int[n];



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

            arr[i] = fr.nextInt();

        }



        return arr;

    }



    static class FastReader {

        BufferedReader br;

        StringTokenizer st;



        public FastReader() {

            br = new BufferedReader(

                    new InputStreamReader(System.in));

        }



        String next() {

            while (st == null || !st.hasMoreElements()) {

                try {

                    st = new StringTokenizer(br.readLine());

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }



        int nextInt() {

            return Integer.parseInt(next());

        }



        long nextLong() {

            return Long.parseLong(next());

        }



        double nextDouble() {

            return Double.parseDouble(next());

        }



        String nextLine() {

            String str = "";

            try {

                if (st.hasMoreTokens()) {

                    str = st.nextToken("\n");

                } else {

                    str = br.readLine();

                }

            } catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }

    }



}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    for(auto x : graph[p.second]){
        st.erase({degree[x], x});
        graph[x].erase(p.second);
        degree[x]--;
        st.insert({degree[x], x});
    }
    
    
    auto it = st.rbegin();
    
    int ans = p.first - 1;
    
    it = st.rbegin();
    ans += it->first;
    
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}

Submission (verdict: Wrong answer on test 4):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    auto it = st.rbegin();
    
    int ans = p.first - 1;
    
    int mx = 0;
    for(auto pp : st){
      if(graph[p.second].count(pp.second)){
        mx = max(mx, pp.first - 1);
      }else{
        mx = max(mx, pp.first);
      }
    }
    
    cout << ans + mx << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    auto it = st.rbegin();
    
    int ans = p.first - 1;
    
    int mx = 0;
    for(auto pp : st){
      if(graph[p.second].count(pp.second)){
        mx = max(mx, pp.first - 1);
      }else{
        mx = max(mx, pp.first);
      }
    }
    
    ans += mx;
    
    auto q = *st.rbegin();
    st.erase(prev(st.end()));
    
    st.insert(p);
    
    for(auto pp : st){
      if(graph[q.second].count(pp.second)){
        ans = max(ans, q.first - 1 + pp.first - 1);
      }else{
        mx = max(mx, q.first - 1 + pp.first);
      }
    }
    
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}

Submission (verdict: Accepted):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    auto it = st.rbegin();
    
    int ans = p.first;
    
    int mx = -1e9;
    for(auto pp : st){
      if(graph[p.second].count(pp.second)){
        mx = max(mx, pp.first - 2);
      }else{
        mx = max(mx, pp.first - 1);
      }
    }
    
    ans += mx;
    
    auto q = *st.rbegin();
    st.erase(prev(st.end()));
    
    st.insert(p);
    
    for(auto pp : st){
      if(graph[q.second].count(pp.second)){
        ans = max(ans, q.first + pp.first - 2);
      }else{
        ans = max(ans, q.first + pp.first - 1);
      }
    }
    
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    auto it = st.rbegin();
    
    int ans = p.first - 1;
    
    int mx = 0;
    for(auto pp : st){
      if(graph[p.second].count(pp.second)){
        mx = max(mx, pp.first - 1);
      }else{
        mx = max(mx, pp.first);
      }
    }
    
    cout << ans + mx << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}

Submission (verdict: Wrong answer on test 4):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    auto it = st.rbegin();
    
    int ans = p.first - 1;
    
    int mx = 0;
    for(auto pp : st){
      if(graph[p.second].count(pp.second)){
        mx = max(mx, pp.first - 1);
      }else{
        mx = max(mx, pp.first);
      }
    }
    
    ans += mx;
    
    auto q = *st.rbegin();
    st.erase(prev(st.end()));
    
    st.insert(p);
    
    for(auto pp : st){
      if(graph[q.second].count(pp.second)){
        ans = max(ans, q.first - 1 + pp.first - 1);
      }else{
        mx = max(mx, q.first - 1 + pp.first);
      }
    }
    
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 4):
/* Author: S. Nithish Kumar :: nithish654 :: */
#include <bits/stdc++.h>
using namespace std;

#define int long long 

const int N = 2e5 + 10, M = 1e9 + 7, mod = 998244353, INF = 1e18;

bool test_cases = true;
void solution(){
    int n; cin >> n;
    vector<set<int>> graph(n + 1);
    vector<int> degree(n + 1, 0);
    
    for(int i = 0; i < n - 1; i++){
        int u, v; cin >> u >> v;
        graph[u].insert(v);
        graph[v].insert(u);
        degree[u]++;
        degree[v]++;
    }
    
    set<pair<int, int>> st;
    for(int i = 1; i <= n; i++){
        st.insert({degree[i], i});
    }
    
    auto p = *prev(st.end());
    st.erase(prev(st.end()));
    
    for(auto x : graph[p.second]){
        st.erase({degree[x], x});
        graph[x].erase(p.second);
        degree[x]--;
        st.insert({degree[x], x});
    }
    
    
    auto it = st.rbegin();
    
    int ans = p.first - 1;
    
    it = st.rbegin();
    ans += it->first;
    
    cout << ans << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);  
    int t = 1; if(test_cases) cin >> t;
    while(t--) solution();
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


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

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

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

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

        vector<int> v(n);
        map<int, int> mpp;

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

        int numDistinct = 0;
        for (pair<int, int> it : mpp)
        {
            numDistinct++;
        }

        vector<int> freq;
        
        for (pair<int, int> it : mpp)
        {
            freq.push_back(it.second);
        }

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

        int i, sum = 0;
        for (i = 0; i<n; i++)
        {
            sum += freq[i];
            if (sum>k) break;
        }

        cout << numDistinct - i << endl;
    }

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

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

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

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

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

        vector<int> v(n);
        map<int, int> mpp;

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

        int numDistinct = 0;
        for (pair<int, int> it : mpp)
        {
            numDistinct++;
        }

        vector<int> freq;
        
        for (pair<int, int> it : mpp)
        {
            freq.push_back(it.second);
        }

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

        int i, sum = 0;
        for (i = 0; i<freq.size(); i++)
        {
            sum += freq[i];
            if (sum>k) break;
        }

        cout << numDistinct - i << endl;
    }

    return 0;
}

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

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

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

        vector<int> v(n);
        map<int, int> mpp;

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

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

        int numDistinct = mpp.size();

        vector<int> freq;
        
        for (pair<int, int> it : mpp)
        {
            freq.push_back(it.second);
        }

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

        int i, sum = 0;
        for (i = 0; i<freq.size(); i++)
        {
            sum += freq[i];
            if (sum>k) break;
        }

        cout << numDistinct - i << endl;
    }

    return 0;
}