ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include <queue>
#include <string.h>
#include <stack>

using namespace std;

typedef long long LL;	
typedef pair<int ,int> PII;

const int N = 2e5 + 10 ;
const int MOD = 1e9 + 7;
const int LOGN = 20;

int a[N]; 
void solve()
{
	int n;cin>>n;
	for(int i = 1; i <= n ; i++)cin>>a[i];
	vector<PII>ans;
	for(int i = 1; i <= n ; i++)
	{
		for(int j = i - 1; j >= 1 ; j--)
		{
			if (a[i] > a[j])
			{
				ans.push_back({a[j],a[i]});
				ans.push_back({a[i],a[j]});
			}
		}

	}
	for(int i = 1; i <= n ; i++)
			
		for(int j = i + 1; j <= n ; j++)
			{
				if (a[i] >= a[j])
					ans.push_back({a[i],a[j]});
			}	
//	int st = 1;
//	for(int i = 1; i < n ; i++)
//	{
//		if (a[i] < a[i + 1])continue;
//		else{
//			for(int r = i ; r > st ; r--)
//				for(int j = r - 1;  j >= st ; j--)
//					ans.push_back({a[r],a[j]});
//					
//			for(int j = st ; j < i ; j++)
//				for(int k = j + 1; k <= i ; k++)
//					ans.push_back({a[j],a[k]});
//			st = i + 1;
//		}
//	}
//	for(int r = n ; r > st ; r--)
//		for(int j = r - 1;  j >= st ; j--)
//			ans.push_back({a[r],a[j]});
//					
//	for(int j = st ; j < n ; j++)
//		for(int k = j + 1; k <= n ; k++)
//			ans.push_back({a[j],a[k]});
			
	cout << ans.size() << endl;
	for(int i = 0 ; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
} 
int main()
{ 
	solve();
	return 0; 
}



Submission (verdict: Wrong answer on test 4):
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include <queue>
#include <string.h>
#include <stack>

using namespace std;

typedef long long LL;	
typedef pair<int ,int> PII;

const int N = 2e5 + 10 ;
const int MOD = 1e9 + 7;
const int LOGN = 20;

int a[N]; 
void solve()
{
	int n;cin>>n;
	for(int i = 1; i <= n ; i++)cin>>a[i];
	vector<PII>ans;
	for(int i = 1; i <= n ; i++)
	{
		for(int j = i - 1; j >= 1 ; j--)
		{
			if (a[i] > a[j])
			{
				ans.push_back({a[i],a[j]});
				ans.push_back({a[j],a[i]});
			}
		}

	}
	for(int i = 1; i <= n ; i++)
			
		for(int j = i + 1; j <= n ; j++)
			{
				if (a[i] >= a[j])
					ans.push_back({a[i],a[j]});
			}	
//	int st = 1;
//	for(int i = 1; i < n ; i++)
//	{
//		if (a[i] < a[i + 1])continue;
//		else{
//			for(int r = i ; r > st ; r--)
//				for(int j = r - 1;  j >= st ; j--)
//					ans.push_back({a[r],a[j]});
//					
//			for(int j = st ; j < i ; j++)
//				for(int k = j + 1; k <= i ; k++)
//					ans.push_back({a[j],a[k]});
//			st = i + 1;
//		}
//	}
//	for(int r = n ; r > st ; r--)
//		for(int j = r - 1;  j >= st ; j--)
//			ans.push_back({a[r],a[j]});
//					
//	for(int j = st ; j < n ; j++)
//		for(int k = j + 1; k <= n ; k++)
//			ans.push_back({a[j],a[k]});
			
	cout << ans.size() << endl;
	for(int i = 0 ; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
} 
int main()
{ 
	solve();
	return 0; 
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 7):
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include <queue>
#include <string.h>
#include <stack>

using namespace std;

typedef long long LL;	
typedef pair<int ,int> PII;

const int N = 2e5 + 10 ;
const int MOD = 1e9 + 7;
const int LOGN = 20;

int a[N]; 
void solve()
{
	int n;cin>>n;
	for(int i = 1; i <= n ; i++)cin>>a[i];
	vector<PII>ans;
	for(int i = 1; i <= n ; i++)
		for(int j = i + 1; j <= n ; j++)
		{
			if (a[i] >= a[j])
				ans.push_back({a[i],a[j]});
		}
	int st = 1;
	for(int i = 1; i < n ; i++)
	{
		if (a[i] < a[i + 1])continue;
		else{
			for(int r = i ; r > st ; r--)
				for(int j = r - 1;  j >= st ; j--)
					ans.push_back({a[r],a[j]});
					
			for(int j = st ; j < i ; j++)
				for(int k = j + 1; k <= i ; k++)
					ans.push_back({a[j],a[k]});
			st = i + 1;
		}
	}
	for(int r = n ; r > st ; r--)
		for(int j = r - 1;  j >= st ; j--)
			ans.push_back({a[r],a[j]});
					
	for(int j = st ; j < n ; j++)
		for(int k = j + 1; k <= n ; k++)
			ans.push_back({a[j],a[k]});
			
	cout << ans.size() << endl;
	for(int i = 0 ; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
} 
int main()
{ 
	solve();
	return 0; 
}



Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include <queue>
#include <string.h>
#include <stack>

using namespace std;

typedef long long LL;	
typedef pair<int ,int> PII;

const int N = 2e5 + 10 ;
const int MOD = 1e9 + 7;
const int LOGN = 20;

int a[N]; 
void solve()
{
	int n;cin>>n;
	for(int i = 1; i <= n ; i++)cin>>a[i];
	vector<PII>ans;
	for(int i = 1; i <= n ; i++)
	{
		for(int j = i - 1; j >= 1 ; j--)
		{
			if (a[i] > a[j])
			{
				ans.push_back({a[j],a[i]});
				ans.push_back({a[i],a[j]});
			}
		}

	}
	for(int i = 1; i <= n ; i++)
			
		for(int j = i + 1; j <= n ; j++)
			{
				if (a[i] >= a[j])
					ans.push_back({a[i],a[j]});
			}	
//	int st = 1;
//	for(int i = 1; i < n ; i++)
//	{
//		if (a[i] < a[i + 1])continue;
//		else{
//			for(int r = i ; r > st ; r--)
//				for(int j = r - 1;  j >= st ; j--)
//					ans.push_back({a[r],a[j]});
//					
//			for(int j = st ; j < i ; j++)
//				for(int k = j + 1; k <= i ; k++)
//					ans.push_back({a[j],a[k]});
//			st = i + 1;
//		}
//	}
//	for(int r = n ; r > st ; r--)
//		for(int j = r - 1;  j >= st ; j--)
//			ans.push_back({a[r],a[j]});
//					
//	for(int j = st ; j < n ; j++)
//		for(int k = j + 1; k <= n ; k++)
//			ans.push_back({a[j],a[k]});
			
	cout << ans.size() << endl;
	for(int i = 0 ; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << endl;
} 
int main()
{ 
	solve();
	return 0; 
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;

int main() {
	int T;
	scanf("%d", &T);
	
	while (T--) {
		int n, m;
		scanf("%d%d", &n, &m);
		
		map<int, int> mp;
		for (int i = 0; i < n; i++) {
			int x;
			scanf("%d", &x);
			mp[x]++;
		}
		map<int, int> st;
		for (int i = 0; i < m; i++) {
			int x;
			scanf("%d", &x);
			st[x]++;
		}
		
		priority_queue<int, vector<int>, greater<int> > a, b;
		for (auto it : mp) {
			int c = it.first, d = it.second;
			if (st[c]) {
				int x = min(d, st[c]);
				d -= x;
				st[c] -= x;
				for (int i = 0; i < d; i++) {
					a.push(c);
				}
			} else {
				for (int i = 0; i < d; i++) {
					a.push(c);
				}
			}
		}
		for (auto it : st) {
			for (int i = 0; i < it.second; i++) {
				b.push(it.first);
			}
		}
		
		bool ok = true;
		while (!b.empty() && !a.empty()) {
			int btop = b.top();
			int a1 = a.top();
			a.pop();
			int a2 = a.top();
			a.pop();
			
			if (a1 == btop) {
				b.pop();
			} else {
				if (abs(a1 - a2) <= 1) {
					a.push(a1 + a2);
				} else {
					ok = false;
					break;
				}
			}
		}
		if (!b.empty() || a.size()) {
			ok = false;
		}
		if (ok) {
			puts("Yes");
		} else {
			puts("No");
		}
	}
	
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

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

int main() {
	int T;
	scanf("%d", &T);
	
	while (T--) {
		int n, m;
		scanf("%d%d", &n, &m);
		
		priority_queue<int> a, b;
		for (int i = 0; i < n; i++) {
			int x;
			scanf("%d", &x);
			a.push(x);
		}
		for (int i = 0; i < m; i++) {
			int x;
			scanf("%d", &x);
			b.push(x);
		}
		
		bool ok = true;
		while (!a.empty()) {
			if (b.empty() || b.size() > a.size()) {
				ok = false;
				break;
			}
			
			int x = b.top();
			b.pop();
			
			if (x < a.top()) {
				ok = false;
				break;
			}
			if (x == a.top()) {
				a.pop();
			} else {
				b.push(x / 2);
				b.push(x / 2 + 1);
			}
		}
		
		if (!b.empty()) {
			ok = false;
		}
		
		if (ok) {
			puts("Yes");
		} else {
			puts("No");
		}
	}
	
    return 0;
}


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

int main() {
	int T;
	scanf("%d", &T);
	
	while (T--) {
		int n, m;
		scanf("%d%d", &n, &m);
		
		priority_queue<int> a, b;
		for (int i = 0; i < n; i++) {
			int x;
			scanf("%d", &x);
			a.push(x);
		}
		for (int i = 0; i < m; i++) {
			int x;
			scanf("%d", &x);
			b.push(x);
		}
		
		bool ok = true;
		while (!a.empty()) {
			if (b.empty() || b.size() > a.size()) {
				ok = false;
				break;
			}
			
			int x = b.top();
			b.pop();
			
			if (x < a.top()) {
				ok = false;
				break;
			}
			if (x == a.top()) {
				a.pop();
			} else {
				b.push(x / 2);
				b.push((x + 1) / 2);
			}
		}
		
		if (!b.empty()) {
			ok = false;
		}
		
		if (ok) {
			puts("Yes");
		} else {
			puts("No");
		}
	}
	
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;

int main() {
	int T;
	scanf("%d", &T);
	
	while (T--) {
		int n, m;
		scanf("%d%d", &n, &m);
		
		map<int, int> mp;
		for (int i = 0; i < n; i++) {
			int x;
			scanf("%d", &x);
			mp[x]++;
		}
		map<int, int> st;
		for (int i = 0; i < m; i++) {
			int x;
			scanf("%d", &x);
			st[x]++;
		}
		
		priority_queue<int, vector<int>, greater<int> > a, b;
		for (auto it : mp) {
			int c = it.first, d = it.second;
			if (st[c]) {
				int x = min(d, st[c]);
				d -= x;
				st[c] -= x;
				for (int i = 0; i < d; i++) {
					a.push(c);
				}
			} else {
				for (int i = 0; i < d; i++) {
					a.push(c);
				}
			}
		}
		for (auto it : st) {
			for (int i = 0; i < it.second; i++) {
				b.push(it.first);
			}
		}
		
		bool ok = true;
		while (!b.empty() && !a.empty()) {
			int btop = b.top();
			int a1 = a.top();
			a.pop();
			int a2 = a.top();
			a.pop();
			
			if (a1 == btop) {
				b.pop();
			} else {
				if (abs(a1 - a2) <= 1) {
					a.push(a1 + a2);
				} else {
					ok = false;
					break;
				}
			}
		}
		if (!b.empty() || a.size()) {
			ok = false;
		}
		if (ok) {
			puts("Yes");
		} else {
			puts("No");
		}
	}
	
    return 0;
}


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

int main() {
	int T;
	scanf("%d", &T);
	
	while (T--) {
		int n, m;
		scanf("%d%d", &n, &m);
		
		priority_queue<int> a, b;
		for (int i = 0; i < n; i++) {
			int x;
			scanf("%d", &x);
			a.push(x);
		}
		for (int i = 0; i < m; i++) {
			int x;
			scanf("%d", &x);
			b.push(x);
		}
		
		bool ok = true;
		while (!a.empty()) {
			if (b.empty() || b.size() > a.size()) {
				ok = false;
				break;
			}
			
			int x = b.top();
			b.pop();
			
			if (x < a.top()) {
				ok = false;
				break;
			}
			if (x == a.top()) {
				a.pop();
			} else {
				b.push(x / 2);
				b.push(x / 2 + 1);
			}
		}
		
		if (!b.empty()) {
			ok = false;
		}
		
		if (ok) {
			puts("Yes");
		} else {
			puts("No");
		}
	}
	
    return 0;
}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define INF 2000000000 // 20억

typedef long long ll;



int T;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    cin >> T;

    while(T--) {

        int n,sum = 0;

        cin >> n;

        vector<int> num(n);

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

            cin >> num[i];

            sum += num[i];

        }



        if (sum % n != 0) {cout << "NO" << "\n"; continue;}

        int target = sum / n;



        bool flag = true;

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

            if (num[i-1] > target) {

                if (num[i+1] >= target) {cout << "NO" << "\n"; flag = false; break;}

                else {num[i+1] += num[i-1] - target; num[i-1] = target;}

            }

            else {

                if (num[i-1] < target) {

                    if (num[i+1] < target) {cout << "NO" << "\n"; flag = false; break;}

                    else {num[i+1] -= target-num[i-1]; num[i-1] = target;}

                }

            }

        }



        if (flag) {

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

                if (num[i] != target) {

                    flag = false;

                    cout << "NO" << "\n";

                    break;

                }

            }

        }



        if (flag) cout << "YES" << "\n";

    }

}

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

using namespace std;

#define INF 2000000000 // 20억

typedef long long ll;



int T;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    cin >> T;

    while(T--) {

        int n,sum = 0;

        cin >> n;

        vector<int> num(n);

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

            cin >> num[i];

            sum += num[i];

        }



        if (sum % n != 0) {cout << "NO" << "\n"; continue;}

        int target = sum / n;



        bool flag = true;

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

            if (num[i-1] > target) {

                if (num[i+1] > target) {cout << "NO" << "\n"; flag = false; break;}

                else {num[i+1] += num[i-1] - target; num[i-1] = target;}

            }

            else {

                if (num[i-1] < target) {

                    if (num[i+1] < target) {cout << "NO" << "\n"; flag = false; break;}

                    else {num[i+1] -= target-num[i-1]; num[i-1] = target;}

                }

            }

        }



        if (flag) {

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

                if (num[i] != target) {

                    flag = false;

                    cout << "NO" << "\n";

                    break;

                }

            }

        }



        if (flag) cout << "YES" << "\n";

    }

}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

#define INF 2000000000 // 20억

typedef long long ll;



int T;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    cin >> T;

    while(T--) {

        int n,sum = 0;

        cin >> n;

        vector<int> num(n);

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

            cin >> num[i];

            sum += num[i];

        }



        if (sum % n != 0) {cout << "NO" << "\n"; continue;}

        int target = sum / n;



        bool flag = true;

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

            if (num[i-1] > target) {

                if (num[i+1] >= target) {cout << "NO" << "\n"; flag = false; break;}

                else {num[i+1] += num[i-1] - target; num[i-1] = target;}

            }

            else {

                if (num[i-1] < target) {

                    if (num[i+1] < target) {cout << "NO" << "\n"; flag = false; break;}

                    else {num[i+1] -= target-num[i-1]; num[i-1] = target;}

                }

            }

        }



        if (flag) {

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

                if (num[i] != target) {

                    flag = false;

                    cout << "NO" << "\n";

                    break;

                }

            }

        }



        if (flag) cout << "YES" << "\n";

    }

}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define INF 2000000000 // 20억

typedef long long ll;



int T;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    cin >> T;

    while(T--) {

        int n,sum = 0;

        cin >> n;

        vector<int> num(n);

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

            cin >> num[i];

            sum += num[i];

        }



        if (sum % n != 0) {cout << "NO" << "\n"; continue;}

        int target = sum / n;



        bool flag = true;

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

            if (num[i-1] > target) {

                if (num[i+1] > target) {cout << "NO" << "\n"; flag = false; break;}

                else {num[i+1] += num[i-1] - target; num[i-1] = target;}

            }

            else {

                if (num[i-1] < target) {

                    if (num[i+1] < target) {cout << "NO" << "\n"; flag = false; break;}

                    else {num[i+1] -= target-num[i-1]; num[i-1] = target;}

                }

            }

        }



        if (flag) {

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

                if (num[i] != target) {

                    flag = false;

                    cout << "NO" << "\n";

                    break;

                }

            }

        }



        if (flag) cout << "YES" << "\n";

    }

}

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

using namespace std;

#define INF 2000000000 // 20억

typedef long long ll;



int T;



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    cin >> T;

    while(T--) {

        int n,sum = 0;

        cin >> n;

        vector<int> num(n);

        long long sum1 = 0, sum2 = 0, sum3 = 0, cnt1 = 0, cnt2 = 0;



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

            cin >> num[i];

            if (i%2 == 0) {

                sum1 += num[i];

                cnt1++;

            }

            else {

                sum2 += num[i];

                cnt2++;

            }

            sum3 += num[i];

        }



        if (sum3 % n != 0) {

            cout << "NO" << "\n";

            continue;

        }



        long long target = sum3 / n;

        if (sum1 % cnt1 != 0 || sum2 % cnt2 != 0) {

            cout << "NO" << "\n";

            continue;

        }



        if (sum1 / cnt1 != target) {

            cout << "NO" << "\n";

            continue;

        }

        else if (sum2 / cnt2 != target) {

            cout << "NO" << "\n";

            continue;

        }



        cout << "YES" << "\n";

    }

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;

const ll N = 1e5 + 10;
ll t;
ll n, l, r;
ll a[N];

int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n >> l >> r;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		sort(a + 1, a + 1 + n);
		
		ll sum = 0;
		for (int i = 1; i <= r - l + 1; i++)
			sum += a[i];
		cout << sum << endl;
	}

	return 0;
}

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

#include<algorithm>

using namespace std;



const int N = 1e5 + 10;

int t, n, r, l;

int a[N], sum[N];



int main()

{

	cin >> t;

	while (t--)

	{

		cin >> n >> l >> r;

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

			cin >> a[i];



		if (l > 1 && r < n)

		{

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

			sort(a + l, a + r);

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

		}

		else if (l == 1 && r < n)

		{

			sort(a + 1, a + r);

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

		}

		else if (l > 1 && r == n)

		{

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

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

		}

		else

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



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

			//cout << a[i] << " ";

		//cout << endl;



		if (l > 1)

		{

			sum[0] = 0;

			for (int i = 1; i <= l - 1; i++)

				sum[i] = sum[i - 1] + a[i];

		}

		sum[r] = a[r];

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

			sum[i] = sum[i + 1] + a[i];

		if (r < n)

		{

			sum[r + 1] = a[r + 1];

			for (int i = r + 2; i <= n; i++)

				sum[i] = sum[i - 1] + a[i];

		}



		//左边

		int ans1 = sum[l];

		if (l > 1)

		{

			for (int i = 1; i <= min(l - 1, r - l + 1); i++)

			{

				if (sum[i] < sum[r - i + 1])

					ans1 = min(ans1, sum[l] - sum[r - i + 1] + sum[i]);

			}

		}



		//右边

		int ans2 = sum[l];

		if (r < n)

		{

			for (int i = r + 1; i <= min(n, r + 1 + r - l); i++)

			{

				if (sum[i] < sum[r - (i - r) + 1])

					ans2 = min(ans2, sum[l] - sum[r - (i - r) + 1] + sum[i]);

			}

		}



		int ans = min(ans1, ans2);

		cout << ans << endl;



	}



	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

#include<algorithm>

using namespace std;



const int N = 1e5 + 10;

int t, n, r, l;

int a[N], sum[N];



int main()

{

	cin >> t;

	while (t--)

	{

		cin >> n >> l >> r;

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

			cin >> a[i];



		if (l > 1 && r < n)

		{

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

			sort(a + l, a + r);

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

		}

		else if (l == 1 && r < n)

		{

			sort(a + 1, a + r);

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

		}

		else if (l > 1 && r == n)

		{

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

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

		}

		else

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



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

			//cout << a[i] << " ";

		//cout << endl;



		if (l > 1)

		{

			sum[0] = 0;

			for (int i = 1; i <= l - 1; i++)

				sum[i] = sum[i - 1] + a[i];

		}

		sum[r] = a[r];

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

			sum[i] = sum[i + 1] + a[i];

		if (r < n)

		{

			sum[r + 1] = a[r + 1];

			for (int i = r + 2; i <= n; i++)

				sum[i] = sum[i - 1] + a[i];

		}



		//左边

		int ans1 = sum[l];

		if (l > 1)

		{

			for (int i = 1; i <= min(l - 1, r - l + 1); i++)

			{

				if (sum[i] < sum[r - i + 1])

					ans1 = min(ans1, sum[l] - sum[r - i + 1] + sum[i]);

			}

		}



		//右边

		int ans2 = sum[l];

		if (r < n)

		{

			for (int i = r + 1; i <= min(n, r + 1 + r - l); i++)

			{

				if (sum[i] < sum[r - (i - r) + 1])

					ans2 = min(ans2, sum[l] - sum[r - (i - r) + 1] + sum[i]);

			}

		}



		int ans = min(ans1, ans2);

		cout << ans << endl;



	}



	return 0;

}

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

#include<algorithm>

using namespace std;



const int N = 1e5 + 10;

int t, n, r, l;

int a[N], sum[N];



int main()

{

	cin >> t;

	while (t--)

	{

		cin >> n >> l >> r;

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

			cin >> a[i];



		if (l > 1 && r < n)

		{

			sort(a + 1, a + l);

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

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

		}

		else if (l == 1 && r < n)

		{

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

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

		}

		else if (l > 1 && r == n)

		{

			sort(a + 1, a + l);

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

		}

		else

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



		cout << endl;



		if (l > 1)

		{

			sum[0] = 0;

			for (int i = 1; i <= l - 1; i++)

				sum[i] = sum[i - 1] + a[i];

		}

		sum[r] = a[r];

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

			sum[i] = sum[i + 1] + a[i];

		if (r < n)

		{

			sum[r + 1] = a[r + 1];

			for (int i = r + 2; i <= n; i++)

				sum[i] = sum[i - 1] + a[i];

		}



		//左边

		int ans1 = sum[l];

		if (l > 1)

		{

			for (int i = 1; i <= min(l - 1, r - l + 1); i++)

			{

				if (sum[i] < sum[r - i + 1])

					ans1 = min(ans1, sum[l] - sum[r - i + 1] + sum[i]);

			}

		}



		//右边

		int ans2 = sum[l];

		if (r < n)

		{

			for (int i = r + 1; i <= min(n, r + 1 + r - l); i++)

			{

				if (sum[i] < sum[r - (i - r) + 1])

					ans2 = min(ans2, sum[l] - sum[r - (i - r) + 1] + sum[i]);

			}

		}



		int ans = min(ans1, ans2);

		cout << ans << endl;



	}



	return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e5 + 10;
int t;
int n, l, r;
int a[N];

int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n >> l >> r;
		for (int i = 1; i <= n; i++)
			cin >> a[i];
		sort(a + 1, a + 1 + n);
		
		int sum = 0;
		for (int i = 1; i <= r - l + 1; i++)
			sum += a[i];
		cout << sum << endl;
	}

	return 0;
}