ShaysXIA/CodeInsightBench huggingface dataset:
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<pair<int,int>> b;
  set<pair<int,int>> edges;
  vector<int> degree(n,0);
  
  for (int i = 0; i < n-1; i++) {
    int u,v;
    cin >> u >> v;
    u--; v--;
    
    degree[u]++;
    degree[v]++;
    edges.insert(make_pair(u,v));
    edges.insert(make_pair(v,u));
  }
  
  for (int i = 0; i <= n-1; i++) {
    b.push_back(make_pair(degree[i],i));
  }
  sort(b.begin(), b.end(), greater<pair<int,int>>());
  
  if (n == 2) {cout << 0 << endl; return;}
  
  int M = b[0].first, N = b[1].first, K = b[2].first;
  
  if (M == N && N == K) {
    cout << 2*M - 1 << endl;
    return;
  } else if (M == N && N > K) {
    if (edges.find(make_pair(b[0].second, b[1].second)) != edges.end()) {
      cout << M+N-2 << endl;
    } else {
      cout << 2*M-1 << endl;
    }
    return;
  } else if (M > N && N == K) {
    int flag = 0;
    for (int i = 1; i < n; i++) {
      if (b[i].first != b[1].first) break; 
      if (edges.find(make_pair(b[0].second, b[i].second)) == edges.end()) {
        flag = 1;
        break;
      }
    }
    
    if (flag) {
      cout << M+N-1 << endl;
    } else {
      cout << M+N-2 << endl;
    }
    return;
  } else {
    cout << M+N-1 << endl;
    return;
  }
  
  return;
}

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<pair<int,int>> b;
  set<pair<int,int>> edges;
  vector<int> degree(n,0);
  
  for (int i = 0; i < n-1; i++) {
    int u,v;
    cin >> u >> v;
    u--; v--;
    
    degree[u]++;
    degree[v]++;
    edges.insert(make_pair(u,v));
    edges.insert(make_pair(v,u));
  }
  
  for (int i = 0; i <= n-1; i++) {
    b.push_back(make_pair(degree[i],i));
  }
  sort(b.begin(), b.end(), greater<pair<int,int>>());
  
  if (n == 2) {cout << 0 << endl; return;}
  
  int M = b[0].first, N = b[1].first, K = b[2].first;
  
  if (M == N && N == K) {
    cout << 2*M - 1 << endl;
    return;
  } else if (M == N && N > K) {
    if (edges.find(make_pair(b[0].second, b[1].second)) != edges.end()) {
      cout << M+N-2 << endl;
    } else {
      cout << 2*M-1 << endl;
    }
    return;
  } else if (M > N) {
    int flag = 0;
    for (int i = 1; i < n; i++) {
      if (b[i].first != b[1].first) break; 
      if (edges.find(make_pair(b[0].second, b[i].second)) == edges.end()) {
        flag = 1;
        break;
      }
    }
    
    if (flag) {
      cout << M+N-1 << endl;
    } else {
      cout << M+N-2 << endl;
    }
    return;
  }
  
  return;
}

int main() {
  int t; cin >> t;
  while (t--) {
    solve();
  }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;


unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


long long power(long long a, long long b, long long m){
    if (b==0) return 1;
    if (b==1) return a%m;
    
    long long temp=power(a,b/2,m)%m;
    if (b%2) return (temp*temp*a)%m;
    else return (temp*temp)%m;
}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        for (int i=0; i<n; i++){
            ans2+=pow(-1,i)*nos[i]*nChoosek(n-1,i);
        }
        
        cout<<max(abs(ans2), ans1)<<endl;
        
        
    }
}



Submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;


long long nChoosek( long long n, long long k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    long long result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


long long power(long long a, long long b, long long m){
    if (b==0) return 1;
    if (b==1) return a%m;
    
    long long temp=power(a,b/2,m)%m;
    if (b%2) return (temp*temp*a)%m;
    else return (temp*temp)%m;
}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        
        for (int i=0; i<n; i++){
            ans2+=pow(-1,i)*nos[i]*nChoosek(n-1,i);
        }
        
        cout<<max(abs(ans2), ans1)<<endl;
        
        
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;

long long power(long long a, long long b, long long m){
    if (b==0) return 1;
    if (b==1) return a%m;
    
    long long temp=power(a,b/2,m)%m;
    if (b%2) return (temp*temp*a)%m;
    else return (temp*temp)%m;
}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    vector<long long> factorials;
    factorials.push_back(1);
    for (int i=1; i<=49; i++){
        factorials.push_back(factorials[factorials.size()-1]*i);
    }
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        for (int i=0; i<n; i++){
            ans2+=pow(-1,i)*nos[i]*factorials[(n-1)]/(factorials[(i)]*factorials[(n-i-1)]);
        }
        
        cout<<max(abs(ans2), ans1)<<endl;
        
        
    }
}


Submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;


unsigned nChoosek( unsigned n, unsigned k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


long long power(long long a, long long b, long long m){
    if (b==0) return 1;
    if (b==1) return a%m;
    
    long long temp=power(a,b/2,m)%m;
    if (b%2) return (temp*temp*a)%m;
    else return (temp*temp)%m;
}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        for (int i=0; i<n; i++){
            ans2+=pow(-1,i)*nos[i]*nChoosek(n-1,i);
        }
        
        cout<<max(abs(ans2), ans1)<<endl;
        
        
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;


long long nChoosek( long long n, long long k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    long long result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


long long power(long long a, long long b, long long m){
    if (b==0) return 1;
    if (b==1) return a%m;
    
    long long temp=power(a,b/2,m)%m;
    if (b%2) return (temp*temp*a)%m;
    else return (temp*temp)%m;
}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        
        for (int i=0; i<n; i++){
            ans2+=pow(-1,i)*nos[i]*nChoosek(n-1,i);
        }
        
        cout<<max(abs(ans2), ans1)<<endl;
        
        
    }
}



Submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;


long long nChoosek( long long n, long long k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    long long result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i;
    }
    return result;
}


//long long power(long long a, long long b, long long m){
//    if (b==0) return 1;
//    if (b==1) return a%m;
//    
//    long long temp=power(a,b/2,m)%m;
//    if (b%2) return (temp*temp*a)%m;
//    else return (temp*temp)%m;
//}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        vector<long long> diffs;
        for (int i=1; i<=n-1; i++){
            for (int i=0; i<nos.size()-1; i++){
                int x=nos[i]-nos[i+1];
                ans2+=x;
                diffs.push_back(x);
            }
            nos=diffs;
            diffs.clear();
//            cout<<nos.size()<<"size"<<diffs.size()<<endl;

            if (abs(ans2)>ans1) ans1=abs(ans2);
            ans2=0;
        }
        
        cout<<ans1<<endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):

#include <iostream>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

int mod1=998244353;
using namespace std;

long long power(long long a, long long b, long long m){
    if (b==0) return 1;
    if (b==1) return a%m;
    
    long long temp=power(a,b/2,m)%m;
    if (b%2) return (temp*temp*a)%m;
    else return (temp*temp)%m;
}

long long max(long long a, long long b){
    if (a<b) return b;
    return a;
}

int main(){
    int t,n,x;
    cin>>t;
    
    vector<long long> factorials;
    factorials.push_back(1);
    for (int i=1; i<=49; i++){
        factorials.push_back(factorials[factorials.size()-1]*i);
    }
    
    while (t--){
        cin>>n;
        vector<long long>nos;
        long long ans1=0;
        long long ans2=0;
        for (int i=0; i<n; i++){
            cin>>x;
            nos.push_back(x);
            ans1+=x;
        }
        
        if (n==1){
            cout<<x<<endl;
            continue;
        }
        for (int i=0; i<n; i++){
            ans2+=pow(-1,i)*nos[i]*factorials[(n-1)]/(factorials[(i)]*factorials[(n-i-1)]);
        }
        
        cout<<max(abs(ans2), ans1)<<endl;
        
        
    }
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

bool isBigger(const string& a, const string& b) {
	if (a.size() > b.size()) return true;
	if (a.size() < b.size()) return false;

	return a > b;
}

void solve() {
	string x;
	cin >> x;

	int currentDigit = 1;

	while (currentDigit < x.size()) {
		if (currentDigit < 1) currentDigit = 1;
		if (x[currentDigit] == '0') {
			currentDigit++;
			continue;
		}

		string b = x;
		swap(b[currentDigit], b[currentDigit - 1]);
		b[currentDigit - 1]--;

		if (isBigger(b, x)) {
			swap(x[currentDigit], x[currentDigit - 1]);
			x[currentDigit - 1]--;
			currentDigit -= 2;
		}

		currentDigit++;
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

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

	return 0;
}

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

bool isBigger(const string& a, const string& b) {
	if (a.size() > b.size()) return true;
	if (a.size() < b.size()) return false;

	return a > b;
}

void solve() {
	string x;
	cin >> x;

	int currentDigit = 1;

	while (currentDigit < x.size()) {
		if (currentDigit < 1) currentDigit = 1;
		if (x[currentDigit] == '0') {
			currentDigit++;
			continue;
		}

		string b = x;
		swap(b[currentDigit], b[currentDigit - 1]);
		b[currentDigit - 1]--;

		if (b > x) {
			swap(x[currentDigit], x[currentDigit - 1]);
			x[currentDigit - 1]--;
			currentDigit -= 2;
		}

		currentDigit++;
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

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

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


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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

bool isBigger(const string& a, const string& b) {
	if (a.size() > b.size()) return true;
	if (a.size() < b.size()) return false;

	return a > b;
}

void solve() {
	string x;
	cin >> x;

	int currentDigit = 1;

	while (currentDigit < x.size()) {
		if (currentDigit < 1) currentDigit = 1;
		if (x[currentDigit] == '0') {
			currentDigit++;
			continue;
		}

		string b = x;
		swap(b[currentDigit], b[currentDigit - 1]);
		b[currentDigit - 1]--;

		if (isBigger(b, x)) {
			swap(x[currentDigit], x[currentDigit - 1]);
			x[currentDigit - 1]--;
			currentDigit -= 2;
		}

		currentDigit++;
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

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

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

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

bool isBigger(const string& a, const string& b) {
	if (a.size() > b.size()) return true;
	if (a.size() < b.size()) return false;

	return a > b;
}

void solve() {
	string x;
	cin >> x;

	int currentDigit = 1;

	while (currentDigit < x.size()) {
		if (currentDigit < 1) currentDigit = 1;
		if (x[currentDigit] == '0') {
			currentDigit++;
			continue;
		}

		string b = x;
		swap(b[currentDigit], b[currentDigit - 1]);
		b[currentDigit - 1]--;

		if (b > x) {
			swap(x[currentDigit], x[currentDigit - 1]);
			x[currentDigit - 1]--;
			currentDigit -= 2;
		}

		currentDigit++;
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

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

	return 0;
}

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

#define out(x) #x << " = " << x << " "
#ifndef LOCAL
#define endl "\n"
#define cerr \
	if (false) cerr
#define stdio(true) stdio(false)
#endif

const int MAX_N = 1e5 + 10;
const int INF = 1e9 + 10;

void solve() {
	string x;
	cin >> x;

	for (int i = 1; i < x.size(); i++) {
		int prv = 0;
		while (i - prv - 1 >= 0 && x[i - prv] != '0' && x[i - prv] - 1 > x[i - prv - 1]) {
			x[i - prv] -= 1;
			swap(x[i - prv], x[i - prv - 1]);
			prv++;
		}
	}

	cout << x << endl;
}

int main() {
	ios_base::sync_with_stdio(true);
	cin.tie(NULL);
	cout.tie(NULL);

	int t;
	cin >> t;

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

	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    for (int i = 0; i < n-1; i++)
    {
        v[i]=v[i]-min(v[i],v[i+1]);
        v[i+1]=v[i+1]-min(v[i],v[i+1]);

    }
    for (int i = 0; i < n-1; i++)
    {
        if(v[i]>v[i+1]) 
        {cout<<"NO";
        return ;
        }
    }
    cout<<"yes";
    
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    for (int i = 0; i < n-1; i++)
    {  int f=min(v[i],v[i+1]);
        v[i]=v[i]-f;
        v[i+1]=v[i+1]-f;

    }
    for (int i = 0; i < n; i++)
    {
        if(v[i]>v[i+1]) 
        {cout<<"NO";
        return ;
        }
        
    }
    cout<<"yes";
    
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
    return 0;
}



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

void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    for (int i = 0; i < n-1; i++)
    {  int f=min(v[i],v[i+1]);
        v[i]=v[i]-f;
        v[i+1]=v[i+1]-f;

    }
    for (int i = 0; i < n-1; i++)
    {
        if(v[i]>v[i+1]) 
        {cout<<"NO";
        return ;
        }
       
    }
    cout<<"yes";
    
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    for (int i = 0; i < n-1; i++)
    {
        v[i]=v[i]-min(v[i],v[i+1]);
        v[i+1]=v[i+1]-min(v[i],v[i+1]);

    }
    for (int i = 0; i < n-1; i++)
    {
        if(v[i]>v[i+1]) 
        {cout<<"NO";
        return ;
        }
    }
    cout<<"yes";
    
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
    return 0;
}


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

void solve()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    for (int i = 0; i < n-1; i++)
    {  int f=min(v[i],v[i+1]);
        v[i]=v[i]-f;
        v[i+1]=v[i+1]-f;

    }
    for (int i = 0; i < n; i++)
    {
        if(v[i]>v[i+1]) 
        {cout<<"NO";
        return ;
        }
        
    }
    cout<<"yes";
    
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

#include <vector>

#include <algorithm>

using namespace std;

const int N = 100010;

int t;

void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    int a[N] = {0}, al[N] = {0}, ar[N] = {0};

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

        cin >> a[i];

    sort(a + 1, a + l);

    sort(a + l, a + r + 1);

    sort(a + r + 1, a + n + 1);

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

        al[i] = ar[i] = a[i];



    int tl = 0, tr = 0;

    for (int i = r, j = 1; i >= l; i--)

        if (j < l && al[i] > al[j])

        {

            swap(al[i], al[j]);

            j++;

        }

    for (int i = r, j = r + 1; i >= l; i--)

        if (j <= n && ar[i] > ar[j])

        {

            swap(ar[i], ar[j]);

            j++;

        }

    for (int q = l; q <= r; q++)

        tl += al[q];

    for (int q = l; q <= r; q++)

        tr += ar[q];

    if (tl < tr)

        cout << tl << endl;

    else

        cout << tr << endl;

}

int main()

{

    ios::sync_with_stdio(0),

        cin.tie(0), cout.tie(0);

    cin >> t;

    while (t--)

        solve();

    return 0;

}

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

#include <vector>

#include <algorithm>

using namespace std;

const int N = 100010;

int t;

void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    int a[N] = {0}, al[N] = {0}, ar[N] = {0};

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

        cin >> a[i];

    sort(a + 1, a + l);

    sort(a + l, a + r + 1);

    sort(a + r + 1, a + n + 1);

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

        al[i] = ar[i] = a[i];

    long long tl = 0, tr = 0;

    for (int i = r, j = 1; i >= l; i--)

        if (j < l && al[i] > al[j])

        {

            swap(al[i], al[j]);

            j++;

        }

    for (int i = r, j = r + 1; i >= l; i--)

        if (j <= n && ar[i] > ar[j])

        {

            swap(ar[i], ar[j]);

            j++;

        }

    for (int q = l; q <= r; q++)

        tl += al[q];

    for (int q = l; q <= r; q++)

        tr += ar[q];

    if (tl < tr)

        cout << tl << endl;

    else

        cout << tr << endl;

}

int main()

{

    ios::sync_with_stdio(0),

        cin.tie(0), cout.tie(0);

    cin >> t;

    while (t--)

        solve();

    return 0;

}