ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

void solve(){
    int n; cin >> n;
    vector<array<int, 2>> vt(n - 1);
    for (int i = 0; i < n - 1; i++) cin >> vt[i][0] >> vt[i][1];
    vector<vector<int>> edges(n + 1);
    for (auto &a : vt){
        edges[a[0]].push_back(a[1]);
        edges[a[1]].push_back(a[0]);
    }
    int mx = 0;
    int d;
    for (int i = 1; i <= n; i++){
        if (mx <= edges[i].size()){
            mx = edges[i].size();
            d = i;
        }
    }
    vector<int> sz(n + 1);
    for (int i = 1; i <= n; i++){
        if (i == d) continue;
        for (auto &e : edges[i]){
            sz[i] += (e != d);
        }
    }
    int mx1 = 0;
    int d1;
    for (int i = 1; i <= n; i++){
        if (mx1 <= sz[i]){
            mx1 = sz[i];
            d1 = i;
        }
    }
    cout << mx + mx1 - 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}


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

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

    vector<int> sdeg = deg;
    sort(sdeg.begin(), sdeg.end());
    int ans = 1, mans = 0;
    for (int i = 0; i < n; i++){
        ans = deg[i];
        vector<int> ideg;

        for (auto &j : adj[i])
            ideg.push_back(deg[j]);
        ideg.push_back(deg[i]);
        sort(ideg.begin(), ideg.end(), greater<int>());

        vector<int> rem;     
        for (int &j : ideg){
            if (!sdeg.empty() && sdeg.back() == j){
                sdeg.pop_back();
                rem.push_back(j);
            }
        }
        reverse(rem.begin(), rem.end());

        int mx = ideg[1] - 1;
        if (!sdeg.empty()) mx = sdeg.back();
        for (int &j : rem){
            sdeg.push_back(j);
        }
        mans = max(mans, ans + mx - 1);
    }
    cout << mans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

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

void solve(){
    int n; cin >> n;
    vector<array<int, 2>> vt(n - 1);
    for (int i = 0; i < n - 1; i++) cin >> vt[i][0] >> vt[i][1];
    vector<vector<int>> edges(n + 1);
    for (auto &a : vt){
        edges[a[0]].push_back(a[1]);
        edges[a[1]].push_back(a[0]);
    }
    int mx, mx1;
    mx = mx1 = 0;
    int d, d1;
    for (int i = 1; i <= n; i++){
        if (mx < edges[i].size()){
            mx1 = mx;
            mx = edges[i].size();
            d1 = d;
            d = i;
        }
        else if (mx1 < edges[i].size()){
            mx1 = edges[i].size();
            d1 = i;
        }
    }
    for (int &e : edges[d]){
        if (e == d1){
            cout << mx + mx1 - 2 << '\n';
            return;
        }
    }
    cout << mx + mx1 - 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}


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

void solve(){
    int n; cin >> n;
    vector<array<int, 2>> vt(n - 1);
    for (int i = 0; i < n - 1; i++) cin >> vt[i][0] >> vt[i][1];
    vector<vector<int>> edges(n + 1);
    for (auto &a : vt){
        edges[a[0]].push_back(a[1]);
        edges[a[1]].push_back(a[0]);
    }
    int mx = 0;
    int d;
    for (int i = 1; i <= n; i++){
        if (mx <= edges[i].size()){
            mx = edges[i].size();
            d = i;
        }
    }
    vector<int> sz(n + 1);
    for (int i = 1; i <= n; i++){
        if (i == d) continue;
        for (auto &e : edges[i]){
            sz[i] += (e != d);
        }
    }
    int mx1 = 0;
    int d1;
    for (int i = 1; i <= n; i++){
        if (mx1 <= sz[i]){
            mx1 = sz[i];
            d1 = i;
        }
    }
    cout << mx + mx1 - 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

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

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

    vector<int> sdeg = deg;
    sort(sdeg.begin(), sdeg.end());
    int ans = 1, mans = 0;
    for (int i = 0; i < n; i++){
        ans = deg[i];
        vector<int> ideg;

        for (auto &j : adj[i])
            ideg.push_back(deg[j]);
        ideg.push_back(deg[i]);
        sort(ideg.begin(), ideg.end(), greater<int>());

        vector<int> rem;     
        for (int &j : ideg){
            if (!sdeg.empty() && sdeg.back() == j){
                sdeg.pop_back();
                rem.push_back(j);
            }
        }
        reverse(rem.begin(), rem.end());

        int mx = ideg[1] - 1;
        if (!sdeg.empty()) mx = sdeg.back();
        for (int &j : rem){
            sdeg.push_back(j);
        }
        mans = max(mans, ans + mx - 1);
    }
    cout << mans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    return 0;
}


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

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

    vector<int> sdeg = deg;
    sort(sdeg.begin(), sdeg.end());
    int ans = 1, mans = 0;
    for (int i = 0; i < n; i++){
        ans = deg[i];
        vector<int> ideg;

        for (auto &j : adj[i])
            ideg.push_back(deg[j]);
        ideg.push_back(deg[i]);
        sort(ideg.begin(), ideg.end(), greater<int>());

        vector<int> rem;     
        for (int &j : ideg){
            if (!sdeg.empty() && sdeg.back() == j){
                sdeg.pop_back();
                rem.push_back(j);
            }
        }
        reverse(rem.begin(), rem.end());

        int mx = -1;
        for (int &j : adj[i])
            mx = max(mx, deg[j] - 1);
        if (!sdeg.empty()) mx = sdeg.back();
        for (int &j : rem){
            sdeg.push_back(j);
        }
        mans = max(mans, ans + mx - 1);
    }
    cout << mans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    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;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> cnt(n, 0);
    map<int, set<int>> mp;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        cnt[u]++;
        cnt[v]++;
        mp[u].insert(v);
        mp[v].insert(u);
    }
    int u = -1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] > mx) {
            mx = cnt[i];
            u = i;
        }
    }
    if (u == -1) {
        cout << "0\n";
        return;
    }
    int ans = 1;
    ans += mx - 1;
    for (int v : mp[u]) {
        cnt[v]--;
    }
    cnt[u] = -1;
    u = -1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] >= mx) {
            mx = cnt[i];
            u = i;
        }
    }
    if (u == -1) {
        cout << "0\n";
        return;
    }
    ans += mx - 1;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t; 
    cin >> t; 
    while (t--) {
        solve();
    }

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

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

using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> cnt(n, 0);
    map<int, set<int>> mp;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        cnt[u]++;
        cnt[v]++;
        mp[u].insert(v);
        mp[v].insert(u);
    }
    int u = -1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] > mx) {
            mx = cnt[i];
            u = i;
        }
    }
    if (u == -1) {
        cout << "0\n";
        return;
    }
    int ans = 1;
    ans += mx - 1;
    for (int v : mp[u]) {
        cnt[v]--;
    }
    cnt[u] = -1;
    u = -1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] >= mx) {
            mx = cnt[i];
            u = i;
        }
    }
    if (u == -1) {
        cout << "0\n";
        return;
    }
    ans += mx - 1;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t; 
    cin >> t; 
    while (t--) {
        solve();
    }

    return 0;
}

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

using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> cnt(n, 0);
    map<int, set<int>> mp;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        cnt[u]++;
        cnt[v]++;
        mp[u].insert(v);
        mp[v].insert(u);
    }
    int u = -1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] >= mx) {
            mx = cnt[i];
            u = i;
        }
    }
    if (u == -1) {
        cout << "0\n";
        return;
    }
    int ans = 1;
    ans += mx - 1;
    for (int v : mp[u]) {
        cnt[v]--;
    }
    cnt[u] = -1;
    u = -1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (cnt[i] >= mx) {
            mx = cnt[i];
            u = i;
        }
    }
    if (u == -1) {
        cout << "0\n";
        return;
    }
    ans += mx - 1;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t; 
    cin >> t; 
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=998244353;
void Solve(){
    int n,m;  cin>>n>>m;
    vector<int> v(n),w(m);
    int sum1=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int z=1;
    for(int i=0;i<n-1;i++){
        if(z==1 && abs(v[i+1]-v[i])<=1){
            sum1+=v[i]+v[i+1];
            z=0;
        }
        else if(z==0 && abs(v[i+1]-v[i])<=1){
            sum1+=v[i+1];
        }
        else if(abs(v[i+1]-v[i])>1) z=1;
    }
    int sum2=0;
    for(int i=0;i<m;i++){
        cin>>w[i]; sum2+=w[i];
    }
    if(sum1==sum2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

signed main(){
    int t; cin>>t;
    while(t--){
        Solve();
    }
}

Submission (verdict: Memory limit exceeded on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define dst(v) sort(v.begin(),v.end(),greater<long long>())
#define ast(v) sort(v.begin(),v.end());
#define vi vector<int>
#define input(vec,n) for(int i=0;i<n;i++) cin>>vec[i];
void print(vi a){
    for(auto it:a) cout<<(it)<<" ";
    cout<<endl;
}         
/*CODE*/
void Solve(){
    int n,m; cin>>n>>m;
    vi a(n),b(m);
    input(a,n); input(b,m);
    map<int,int> l;
    priority_queue<int> q;
    for(int i=0;i<n;i++) l[a[i]]++;
    for(int i=0;i<m;i++) q.push(b[i]);
    while(!q.empty()){
        int x=q.top();
        q.pop();
        if(l.find(x)!=l.end()) l[x]--;
        else{
            if(x!=1){
                q.push(x/2);
                q.push(x-(x/2));
            } 
        }
    }
    for(auto it:l){
        if(it.second!=0){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}
signed main(){
    int t; cin>>t;
    while(t--){
        Solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=998244353;
void Solve(){
    int n,m;  cin>>n>>m;
    vector<int> v(n),w(m);
    int sum1=0;
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int z=1;
    for(int i=0;i<n-1;i++){
        if(z==1 && abs(v[i+1]-v[i])<=1){
            sum1+=v[i]+v[i+1];
            z=0;
        }
        else if(z==0 && abs(v[i+1]-v[i])<=1){
            sum1+=v[i+1];
        }
        else if(abs(v[i+1]-v[i])>1) z=1;
    }
    int sum2=0;
    for(int i=0;i<m;i++){
        cin>>w[i]; sum2+=w[i];
    }
    if(sum1==sum2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

signed main(){
    int t; cin>>t;
    while(t--){
        Solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Memory limit exceeded on test 1):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define dst(v) sort(v.begin(),v.end(),greater<long long>())
#define ast(v) sort(v.begin(),v.end());
#define vi vector<int>
#define input(vec,n) for(int i=0;i<n;i++) cin>>vec[i];
void print(vi a){
    for(auto it:a) cout<<(it)<<" ";
    cout<<endl;
}         
/*CODE*/
void Solve(){
    int n,m; cin>>n>>m;
    vi a(n),b(m);
    input(a,n); input(b,m);
    map<int,int> l;
    priority_queue<int> q;
    for(int i=0;i<n;i++) l[a[i]]++;
    for(int i=0;i<m;i++) q.push(b[i]);
    while(!q.empty()){
        int x=q.top();
        q.pop();
        if(l.find(x)!=l.end()) l[x]--;
        else{
            if(x!=1){
                q.push(x/2);
                q.push(x-(x/2));
            } 
        }
    }
    for(auto it:l){
        if(it.second!=0){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}
signed main(){
    int t; cin>>t;
    while(t--){
        Solve();
    }
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define dst(v) sort(v.begin(),v.end(),greater<long long>())
#define ast(v) sort(v.begin(),v.end());
#define vi vector<int>
#define input(vec,n) for(int i=0;i<n;i++) cin>>vec[i];
void print(vi a){
    for(auto it:a) cout<<(it)<<" ";
    cout<<endl;
}         
/*CODE*/
void Solve(){
    int n,m; cin>>n>>m;
    vi a(n),b(m);
    input(a,n); input(b,m);
    map<int,int> l;
    priority_queue<int> q;
    for(int i=0;i<n;i++) l[a[i]]++;
    for(int i=0;i<m;i++) q.push(b[i]);
    sort(a.begin(),a.end());
    if(q.size()==n){
        sort(b.begin(),b.end());
        for(int i=0;i<n;i++){
            if(a[i]!=b[i]){
                cout<<"No"<<endl;
                return;
            }
        }
    }
    else{
        vi z;
        while(q.size()!=n-z.size() && !q.empty()){
            int x=q.top();
            q.pop();
            if(l.find(x)!=l.end() && l[x]!=0){
                z.push_back(x);
                l[x]--;
            }
            else{
                if(x!=1){
                    q.push(x-(x/2));
                    q.push(x/2);
                }
            }
        }
        int x=q.size();
        for(int i=0;i<x;i++){
            z.pb(q.top());
            q.pop();
        }
        ast(z);
        for(int i=0;i<n;i++){
            if(z[i]!=a[i]){
                cout<<"No"<<endl;
                return;
            }
        }
    }
    cout<<"Yes"<<endl;
}
signed main(){
    int t; cin>>t;
    while(t--){
        Solve();
    }
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int n1=a.size();
		int n2=b.size();
		a=' '+a;
		b=' '+b;
		c=' '+c;
		for(int i=0;i<=n1;i++){
			for(int j=0;j<=n2;j++){
				if(i+j==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=1e4;
				dp[i][j]=min(dp[i][j],dp[i-1][j]+!(a[i]==c[j+i]));
				dp[i][j]=min(dp[i][j],dp[i][j-1]+!(b[j]==c[j+i]));
			}
		}
		
		cout<<dp[n1][n2]<<endl;
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int n1=a.size();
		int n2=b.size();
		a=' '+a;
		b=' '+b;
		c=' '+c;
		for(int i=0;i<=n1;i++){
			for(int j=0;j<=n2;j++){
				if(i+j==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=1e9;
				dp[i][j]=min(dp[i][j],dp[i-1][j]+!(a[i]==c[j+i]));
				dp[i][j]=min(dp[i][j],dp[i][j-1]+!(b[j]==c[j+i]));
			}
		}
		
		cout<<dp[n1][n2]<<endl;
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int n1=a.size();
		int n2=b.size();
		a=' '+a;
		b=' '+b;
		c=' '+c;
		for(int i=0;i<=n1;i++){
			for(int j=0;j<=n2;j++){
				if(i+j==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=1e4;
				dp[i][j]=min(dp[i][j],dp[i-1][j]+!(a[i]==c[j+i]));
				dp[i][j]=min(dp[i][j],dp[i][j-1]+!(b[j]==c[j+i]));
			}
		}
		
		cout<<dp[n1][n2]<<endl;
	}
	return 0;
}
Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int n1=a.size();
		int n2=b.size();
		a=' '+a;
		b=' '+b;
		c=' '+c;
		for(int i=0;i<=n1;i++){
			for(int j=0;j<=n2;j++){
				if(i+j==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=1e9;
				dp[i][j]=min(dp[i][j],dp[i-1][j]+!(a[i]==c[j+i]));
				dp[i][j]=min(dp[i][j],dp[i][j-1]+!(b[j]==c[j+i]));
			}
		}
		
		cout<<dp[n1][n2]<<endl;
	}
	return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int n1=a.size();
		int n2=b.size();
		a=' '+a;
		b=' '+b;
		c=' '+c;
		for(int i=0;i<=n1;i++){
			for(int j=0;j<=n2;j++){
				if(i+j==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=1e9;
				if(i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+!(a[i]==c[j+i]));
				if(j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+!(b[j]==c[j+i]));
			}
		}
		
		cout<<dp[n1][n2]<<endl;
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int a[N]; 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        ll sum1=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(i>=l&&i<=r) sum1+=a[i];
        }
        sort(a+1,a+1+n);
        int cnt=0;
        ll sum=0;
        for(int i=1;i<=n;i++){
            if(cnt==r-l+1){
                break;
            }
            sum+=a[i];
            cnt++;
        }
        if(sum1==sum&&(r-l+1)!=n){
            sum-=a[r-l+1];
            sum+=a[r-l+2];
        }
        cout<<sum<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int a[N],b[N]; 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;

        for(int i=1;i<=n;i++){
            cin>>a[i];
            b[i]=a[i];
        }
        sort(a+1,a+1+r);
        sort(b+l,b+n+1);
        ll sum1=0,sum2=0;
        for(int i=1;i<=r-l+1;i++) sum1+=a[i];
        for(int i=l;i<=r;i++) sum2+=b[i];
        sum1=min(sum1,sum2);
        cout<<sum1<<endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int a[N]; 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        for(int i=1;i<=n;i++) cin>>a[i];
        sort(a+1,a+1+n);
        int cnt=0;
        ll sum=0;
        for(int i=1;i<=n;i++){
            if(cnt==r-l+1){
                break;
            }
            sum+=a[i];
            cnt++;
        }
        cout<<sum<<endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int a[N]; 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        ll sum1=0;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(i>=l&&i<=r) sum1+=a[i];
        }
        sort(a+1,a+1+n);
        int cnt=0;
        ll sum=0;
        for(int i=1;i<=n;i++){
            if(cnt==r-l+1){
                break;
            }
            sum+=a[i];
            cnt++;
        }
        if(sum1==sum&&(r-l+1)!=n){
            sum-=a[r-l+1];
            sum+=a[r-l+2];
        }
        cout<<sum<<endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int a[N]; 
int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        for(int i=1;i<=n;i++) cin>>a[i];
        sort(a+1,a+1+n);
        int cnt=0;
        ll sum=0;
        for(int i=1;i<=n;i++){
            if(cnt==r-l+1){
                break;
            }
            sum+=a[i];
            cnt++;
        }
        cout<<sum<<endl;
    }
    return 0;
}