ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define int long long
using namespace std;
int mod=998244353;
int INF=-1e10;
void dfs(int u,int p,auto &adj,auto &dp,auto &dgr){
    for(auto v:adj[u]){
        if(v==p) continue;
        dfs(v,u,adj,dp,dgr);
        dp[u][1][0]=max({dp[u][1][0],dp[v][1][1],dp[v][1][0]});
        dp[u][2][0]=max({dp[u][2][0],dp[v][2][0],dp[v][2][1]});
        dp[u][1][1]=dgr[u];
        dp[u][2][1]=max({dp[u][2][1],dp[v][1][1]+dgr[u]-2,dp[v][1][0]+dgr[u]-1});
    }
    if(dgr[u]==1 && u!=0){
        dp[u][1][0] = 0;
        dp[u][2][0] = 0;
        dp[u][1][1] = 1;
        dp[u][2][1] = 0;
    }
}
void solve(){
    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    vector<vector<vector<int>>> dp(n,vector<vector<int>>(3,vector<int>(2,0)));
    vector<int> dgr(n,0);
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        dgr[u]++;
        dgr[v]++;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0,-1,adj,dp,dgr);
    //cout<<dp[4][1][1]<<endl;
    cout<<max(dp[0][2][0],dp[0][2][1])<<endl;
}
int32_t main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define int long long
using namespace std;
int mod=998244353;
int INF=-1e10;
void dfs(int u,int p,auto &adj,auto &dp,auto &dgr){
    int m1=0;
    int m2=0;
    for(auto v:adj[u]){
        if(v==p) continue;
        dfs(v,u,adj,dp,dgr);
        if(m1<=max(dp[v][1][1],dp[v][1][0])){
            m2=m1;
            m1=max(dp[v][1][1],dp[v][1][0]);
        }
        else if(m2<max(dp[v][1][1],dp[v][1][0])){
            m2=max(dp[v][1][1],dp[v][1][0]);
        }
        dp[u][1][0]=max({dp[u][1][0],dp[v][1][1],dp[v][1][0]});
        dp[u][2][0]=max({dp[u][2][0],dp[v][2][0],dp[v][2][1]});
        dp[u][1][1]=dgr[u];
        dp[u][2][1]=max({dp[u][2][1],dp[v][1][1]+dgr[u]-2,dp[v][1][0]+dgr[u]-1});
    }
    dp[u][2][0]=max(dp[u][2][0],m1+m2-1);
    if(dgr[u]==1){
        dp[u][1][0] = 0;
        dp[u][2][0] = 0;
        dp[u][1][1] = 1;
        dp[u][2][1] = 0;
    }
}
void solve(){
    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    vector<vector<vector<int>>> dp(n,vector<vector<int>>(3,vector<int>(2,0)));
    vector<int> dgr(n,0);
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        dgr[u]++;
        dgr[v]++;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0,-1,adj,dp,dgr);
    //cout<<dp[1][1][1]<<endl;
    cout<<max(dp[0][2][0],dp[0][2][1])<<endl;
}
int32_t main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define int long long
using namespace std;
int mod=998244353;
int INF=-1e10;
void dfs(int u,int p,auto &adj,auto &dp,auto &dgr){
    int m1=0;
    int m2=0;
    for(auto v:adj[u]){
        if(v==p) continue;
        dfs(v,u,adj,dp,dgr);
        if(m1<=max(dp[v][1][1],dp[v][1][0])){
            m2=m1;
            m1=max(dp[v][1][1],dp[v][1][0]);
        }
        else if(m2<max(dp[v][1][1],dp[v][1][0])){
            m2=max(dp[v][1][1],dp[v][1][0]);
        }
        dp[u][1][0]=max({dp[u][1][0],dp[v][1][1],dp[v][1][0]});
        dp[u][2][0]=max({dp[u][2][0],dp[v][2][0],dp[v][2][1]});
        dp[u][1][1]=dgr[u];
        dp[u][2][1]=max({dp[u][2][1],dp[v][1][1]+dgr[u]-2,dp[v][1][0]+dgr[u]-1});
    }
    dp[u][2][0]=max(dp[u][2][0],m1+m2-1);
    if(dgr[u]==1){
        dp[u][1][0] = 0;
        dp[u][2][0] = 0;
        dp[u][1][1] = 1;
        dp[u][2][1] = 0;
    }
}
void solve(){
    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    vector<vector<vector<int>>> dp(n,vector<vector<int>>(3,vector<int>(2,0)));
    vector<int> dgr(n,0);
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        dgr[u]++;
        dgr[v]++;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0,-1,adj,dp,dgr);
    //cout<<dp[1][1][1]<<endl;
    cout<<max(dp[0][2][0],dp[0][2][1])<<endl;
}
int32_t main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define int long long
using namespace std;
int mod=998244353;
int INF=-1e10;
void dfs(int u,int p,auto &adj,auto &dp,auto &dgr){
    int m1=0;
    int m2=0;
    for(auto v:adj[u]){
        if(v==p) continue;
        dfs(v,u,adj,dp,dgr);
        if(m1<=max(dp[v][1][1],dp[v][1][0])){
            m2=m1;
            m1=max(dp[v][1][1],dp[v][1][0]);
        }
        else if(m2<max(dp[v][1][1],dp[v][1][0])){
            m2=max(dp[v][1][1],dp[v][1][0]);
        }
        dp[u][1][0]=max({dp[u][1][0],dp[v][1][1],dp[v][1][0]});
        dp[u][2][0]=max({dp[u][2][0],dp[v][2][0],dp[v][2][1]});
        dp[u][1][1]=dgr[u];
        dp[u][2][1]=max({dp[u][2][1],dp[v][1][1]+dgr[u]-2,dp[v][1][0]+dgr[u]-1});
    }
    dp[u][2][0]=max(dp[u][2][0],m1+m2-1);
    if(dgr[u]==1){
        dp[u][1][1] = 1;
    }
}
void solve(){
    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    vector<vector<vector<int>>> dp(n,vector<vector<int>>(3,vector<int>(2,0)));
    vector<int> dgr(n,0);
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        dgr[u]++;
        dgr[v]++;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0,-1,adj,dp,dgr);
    cout<<max(dp[0][2][0],dp[0][2][1])<<endl;
}
int32_t main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
/* AUTHOR : ashishsutar1210 */

#include<bits/stdc++.h>

using namespace std;

#define ll long long 

#define ld long double

#define i128 __int128_t

#define Endl endl

#define endl '\n' // undef when responsive 

#define F first

#define S second

#define all(x) begin(x),end(x)

#define rall(x) rbegin(x),rend(x)

#define sz  size()

#define pb push_back

#define mpp make_pair

#define yes cout<<"YES"<<endl

#define no cout<<"NO"<<endl

#define fr(i,a,b) for(ll i=a;i<b;++i)

#define rf(i,a,b) for(ll i=a-1;i>=b;--i)

#define lb lower_bound

#define ub upper_bound

#define eb emplace_back

#define INF 3e18



#ifdef local

    #include "./debug.cpp"

#else 

    #define debug(x...)

#endif



const ll mod = 1000000007;



void ash()

{

    int n;

    int mx = -1;

    stack<int>st;

    cin>>n;

    vector<int>a(n);

    fr(i,0,n){

        cin>>a[i];

    }

    vector<int>ng(n);

    rf(i,n,0)

    {

        while(st.sz && a[st.top()]<a[i])

        {

            st.pop();

        }

        if(st.sz)

        {

            ng[i] = st.top();

        }

        else

        {

            ng[i] = n;

        }

        st.push(i);

    }

    int idx = 0;

    while(idx < n-1)

    {

        if(ng[idx] == idx+1)

        {

            idx += 2;

            continue;

        }

        if(ng[idx] == n)

        {

            no;

            return;

        }

        idx += 2;

    }

    yes;

}



int32_t main(){



ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



#ifdef local1

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

   int t = 1;

   cin>>t;

   while(t--){

    ash();

   }

    return 0;

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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define forloop(x,y) for(int i=x;i<y;i++)
#define secondfor(x,y) for(int j=x;j<y;j++)
#define print(x) cout << x << "\n";
#define output(arr) for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
#define asort(v) sort(v.begin(), v.end())
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define intmax INT_MAX
#define intmin INT_MIN
#define lintmax LLONG_MAX
#define lintmin LLONG_MIN
#define mp(x,y) make_pair(x,y)
lint solvefunction(vector<lint>&arr,lint k){
    if(k>=arr.size() || arr.size()==1){return 1;}
    map<lint,lint>mp;
    forloop(0,arr.size()){mp[arr[i]]++;}
    vector<lint>newarr;
    for(auto it=mp.begin();it!=mp.end();it++){
        lint freq=it->second;
        newarr.push_back(freq);
    }
    if(k==0){
        return newarr.size();
    }
    forloop(0,newarr.size()){
        lint frequency = newarr[i];
        if(k>0){
            if(k>=newarr[i]){
                k-=newarr[i];
                newarr[i]=0;
            }
        }
    }lint cnt=0;
    forloop(0,newarr.size()){
        if(newarr[i]>0){cnt++;}
    }
    return cnt;
}

void solution(int test){
    while(test--){
        lint n;lint k;
        cin >> n >> k;
        vector<lint>arr;
        forloop(0,n){lint x;cin >> x;arr.push_back(x);}
        lint ans=solvefunction(arr,k);
        print(ans)

    }
}
int main(){
    int test;
    cin >> test;
    solution(test);
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define forloop(x,y) for(int i=x;i<y;i++)
#define secondfor(x,y) for(int j=x;j<y;j++)
#define print(x) cout << x << "\n";
#define output(arr) for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
#define asort(v) sort(v.begin(), v.end())
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define intmax INT_MAX
#define intmin INT_MIN
#define lintmax LLONG_MAX
#define lintmin LLONG_MIN
#define mp(x,y) make_pair(x,y)
lint solvefunction(vector<lint>&arr,lint k){
    if(k>=arr.size() || arr.size()==1){return 1;}
    map<lint,lint>mp;
    forloop(0,arr.size()){mp[arr[i]]++;}
    vector<lint>newarr;
    for(auto it=mp.begin();it!=mp.end();it++){
        lint freq=it->second;
        newarr.push_back(freq);
    }
    if(k==0){
        return newarr.size();
    }
    sort(newarr.begin(),newarr.end());
    forloop(0,newarr.size()){
        lint frequency = newarr[i];
        if(k>0){
            if(k>=newarr[i]){
                k-=newarr[i];
                newarr[i]=0;
            }
        }
    }lint cnt=0;
    forloop(0,newarr.size()){
        if(newarr[i]>0){cnt++;}
    }
    return cnt;
}

void solution(int test){
    while(test--){
        lint n;lint k;
        cin >> n >> k;
        vector<lint>arr;
        forloop(0,n){lint x;cin >> x;arr.push_back(x);}
        lint ans=solvefunction(arr,k);
        print(ans)

    }
}
int main(){
    int test;
    cin >> test;
    solution(test);
}
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;
#define lint long long
#define forloop(x,y) for(int i=x;i<y;i++)
#define secondfor(x,y) for(int j=x;j<y;j++)
#define print(x) cout << x << "\n";
#define output(arr) for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
#define asort(v) sort(v.begin(), v.end())
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define intmax INT_MAX
#define intmin INT_MIN
#define lintmax LLONG_MAX
#define lintmin LLONG_MIN
#define mp(x,y) make_pair(x,y)
lint solvefunction(vector<lint>&arr,lint k){
    if(k>=arr.size() || arr.size()==1){return 1;}
    map<lint,lint>mp;
    forloop(0,arr.size()){mp[arr[i]]++;}
    vector<lint>newarr;
    for(auto it=mp.begin();it!=mp.end();it++){
        lint freq=it->second;
        newarr.push_back(freq);
    }
    if(k==0){
        return newarr.size();
    }
    forloop(0,newarr.size()){
        lint frequency = newarr[i];
        if(k>0){
            if(k>=newarr[i]){
                k-=newarr[i];
                newarr[i]=0;
            }
        }
    }lint cnt=0;
    forloop(0,newarr.size()){
        if(newarr[i]!=0){cnt++;}
    }
    return cnt;
}

void solution(int test){
    while(test--){
        lint n;lint k;
        cin >> n >> k;
        vector<lint>arr;
        forloop(0,n){lint x;cin >> x;arr.push_back(x);}
        lint ans=solvefunction(arr,k);
        print(ans)

    }
}
int main(){
    int test;
    cin >> test;
    solution(test);
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define forloop(x,y) for(int i=x;i<y;i++)
#define secondfor(x,y) for(int j=x;j<y;j++)
#define print(x) cout << x << "\n";
#define output(arr) for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
#define asort(v) sort(v.begin(), v.end())
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define intmax INT_MAX
#define intmin INT_MIN
#define lintmax LLONG_MAX
#define lintmin LLONG_MIN
#define mp(x,y) make_pair(x,y)
lint solvefunction(vector<lint>&arr,lint k){
    if(k>=arr.size() || arr.size()==1){return 1;}
    map<lint,lint>mp;
    forloop(0,arr.size()){mp[arr[i]]++;}
    vector<lint>newarr;
    for(auto it=mp.begin();it!=mp.end();it++){
        lint freq=it->second;
        newarr.push_back(freq);
    }
    if(k==0){
        return newarr.size();
    }
    forloop(0,newarr.size()){
        lint frequency = newarr[i];
        if(k>0){
            if(k>=newarr[i]){
                k-=newarr[i];
                newarr[i]=0;
            }
        }
    }lint cnt=0;
    forloop(0,newarr.size()){
        if(newarr[i]!=0){cnt++;}
    }
    return cnt;
}

void solution(int test){
    while(test--){
        lint n;lint k;
        cin >> n >> k;
        vector<lint>arr;
        forloop(0,n){lint x;cin >> x;arr.push_back(x);}
        lint ans=solvefunction(arr,k);
        print(ans)

    }
}
int main(){
    int test;
    cin >> test;
    solution(test);
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define forloop(x,y) for(int i=x;i<y;i++)
#define secondfor(x,y) for(int j=x;j<y;j++)
#define print(x) cout << x << "\n";
#define output(arr) for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
#define asort(v) sort(v.begin(), v.end())
#define dsort(v) sort(v.begin(), v.end(), greater<int>())
#define intmax INT_MAX
#define intmin INT_MIN
#define lintmax LLONG_MAX
#define lintmin LLONG_MIN
#define mp(x,y) make_pair(x,y)
lint solvefunction(vector<lint>&arr,lint k){
    if(k>=arr.size() || arr.size()==1){return 1;}
    map<lint,lint>mp;
    forloop(0,arr.size()){mp[arr[i]]++;}
    vector<lint>newarr;
    for(auto it=mp.begin();it!=mp.end();it++){
        lint freq=it->second;
        newarr.push_back(freq);
    }
    if(k==0){
        return newarr.size();
    }
    forloop(0,newarr.size()){
        lint frequency = newarr[i];
        if(k>0){
            if(k>=newarr[i]){
                k-=newarr[i];
                newarr[i]=0;
            }
        }
    }lint cnt=0;
    forloop(0,newarr.size()){
        if(newarr[i]>0){cnt++;}
    }
    return cnt;
}

void solution(int test){
    while(test--){
        lint n;lint k;
        cin >> n >> k;
        vector<lint>arr;
        forloop(0,n){lint x;cin >> x;arr.push_back(x);}
        lint ans=solvefunction(arr,k);
        print(ans)

    }
}
int main(){
    int test;
    cin >> test;
    solution(test);
}
Problem: 2057B - Gorilla and the Exam
Language: C++17 (GCC 7-32)

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

using namespace std;

#define rep(i,j,a) for(int i=j;i<a;i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pi;
typedef unordered_map<int,int> umii;
typedef vector<int> vi;




void solve(){
	int n,k,container;
	cin>>n>>k;
	vector<int> arr(n),frequency(1,1);
	int minimum_operaiton = 0;

	rep(i,0,n){
		cin>>arr[i];
	}

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

	rep(i,1,n){
		if(arr[i] == arr[i-1]){
			frequency.back()++;
		}else{
			frequency.emplace_back(1);
		}
	}


	rep(i,0,frequency.size()){
		if(frequency[i] < k){
			k-= frequency[i];
		}else{
			frequency[i] = frequency[i] - k;
			k = 0;
			minimum_operaiton++;
		}
	}


	if(minimum_operaiton == 0)
		minimum_operaiton++;

	cout<<minimum_operaiton<<"\n";
}

int main(){
	int tc;

	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	cin>>tc;

	while(tc--){
		solve();
	}

	return 0;
}

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

using namespace std;

#define rep(i,j,a) for(int i=j;i<a;i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pi;
typedef unordered_map<int,int> umii;
typedef vector<int> vi;




void solve(){
	int n,k,container;
	cin>>n>>k;
	vector<int> arr(n),frequency(1,1);
	int minimum_operaiton = 0;

	rep(i,0,n){
		cin>>arr[i];
	}

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

	rep(i,1,n){
		if(arr[i] == arr[i-1]){
			frequency.back()++;
		}else{
			frequency.emplace_back(1);
		}
	}

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


	rep(i,0,frequency.size()){
		if(frequency[i] < k){
			k-= frequency[i];
			frequency[i] = 0;
		}else{
			frequency[i] = frequency[i] - k;
			k = 0;
			break;
		}
	}

	rep(i,0,frequency.size()){
		if(frequency[i] > 0){
			minimum_operaiton++;
		}
	}


	if(minimum_operaiton == 0)
		minimum_operaiton++;

	cout<<minimum_operaiton<<"\n";
}

int main(){
	int tc;

	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	cin>>tc;

	while(tc--){
		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;

#define rep(i,a) for(int i=0;i<a;i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pi;
typedef unordered_map<int,int> umii;
typedef vector<int> vi;




void solve(){
	int n,k,container;
	cin>>n>>k;
	int minimum_operaiton = 0;

	umii hashmap;

	rep(i,n){
		cin>>container;
		hashmap[container]++;
	}

	vector<pi> array(hashmap.begin(),hashmap.end());

	int unique_elements = array.size();

	sort(array.begin(),array.end(),[](const auto &p1, const auto &p2){
		return p1.S < p2.S;
	});

	rep(i,unique_elements){
		if(array[i].S < k){
			k-= array[i].S;
			array[i].S = 0;
		}else{
			array[i].S = array[i].S - k;
			k = 0;
			break;
		}
	}

	rep(i, unique_elements){
		if(array[i].S > 0){
			minimum_operaiton++;
		}
	}

	if(minimum_operaiton == 0)
		minimum_operaiton++;

	cout<<minimum_operaiton<<endl;
}

int main(){
	int tc;

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);


	cin>>tc;

	while(tc--){
		solve();
	}

	return 0;
}

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

using namespace std;

#define rep(i,j,a) for(int i=j;i<a;i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pi;
typedef unordered_map<int,int> umii;
typedef vector<int> vi;




void solve(){
	int n,k,container;
	cin>>n>>k;
	vector<int> arr(n),frequency(1,1);
	int minimum_operaiton = 0;

	rep(i,0,n){
		cin>>arr[i];
	}

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

	rep(i,1,n){
		if(arr[i] == arr[i-1]){
			frequency.back()++;
		}else{
			frequency.emplace_back(1);
		}
	}


	rep(i,0,frequency.size()){
		if(frequency[i] < k){
			k-= frequency[i];
		}else{
			frequency[i] = frequency[i] - k;
			k = 0;
			minimum_operaiton++;
		}
	}


	if(minimum_operaiton == 0)
		minimum_operaiton++;

	cout<<minimum_operaiton<<"\n";
}

int main(){
	int tc;

	ios::sync_with_stdio(false);
	cin.tie(nullptr);


	cin>>tc;

	while(tc--){
		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;

#define rep(i,a) for(int i=0;i<a;i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pi;
typedef unordered_map<int,int> umii;
typedef vector<int> vi;




void solve(){
	int n,k,container;
	cin>>n>>k;
	int minimum_operaiton = 0;

	umii hashmap;

	rep(i,n){
		cin>>container;
		hashmap[container]++;
	}

	vector<pi> array(hashmap.begin(),hashmap.end());

	int unique_elements = array.size();

	sort(array.begin(),array.end(),[](const auto &p1, const auto &p2){
		return p1.S < p2.S;
	});

	rep(i,unique_elements){
		if(array[i].S < k){
			k-= array[i].S;
			array[i].S = 0;
		}else{
			array[i].S = array[i].S - k;
			k = 0;
			break;
		}
	}

	rep(i, unique_elements){
		if(array[i].S > 0){
			minimum_operaiton++;
		}
	}

	if(minimum_operaiton == 0)
		minimum_operaiton++;

	cout<<minimum_operaiton<<endl;
}

int main(){
	int tc;

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);


	cin>>tc;

	while(tc--){
		solve();
	}

	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n, l, r;

        cin >> n >> l >> r;

        vector<long long> v(n);

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

            cin >> v[i];

        }

        l--;

      

        vector<long long> u(v.begin() + l, v.end());

        sort(v.begin(), v.begin()+r);

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



        long long sum_w = accumulate(v.begin(), v.begin() + r-l , 0);

        long long sum_u = accumulate(u.begin(), u.begin() + r - l, 0);



        cout << min(sum_w, sum_u) << endl;

    }

    return 0;

}



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

using namespace std;



int main() {

    int t, n, l, r, i, a[200000];

    cin >> t;

    while (t--) {

        cin >> n >> l >> r;

        l--; // Convert to 0-based index

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

            cin >> a[i];

        }

        vector<int> c(a + l, a + n);

        sort(a, a + r);

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

        cout << min(accumulate(a, a + r - l, 0ll), accumulate(c.begin(), c.begin() + r - l, 0ll)) << ' ';

    }

}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


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

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n, l, r;

        cin >> n >> l >> r;

        vector<int> v(n);

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

            cin >> v[i];

        }

        l--;

      

        vector<int> u(v.begin() + l, v.end());

        sort(v.begin(), v.begin()+r);

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



        long long sum_w = accumulate(v.begin(), v.begin() + r-l , 0);

        long long sum_u = accumulate(u.begin(), u.begin() + r - l, 0);



        cout << min(sum_w, sum_u) << endl;

    }

    return 0;

}