ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
int a[100005],b[100005];
//map<int,int>b;
set<int>cot;
struct record
{
	int content;
	int number;
}c[100005];
int compare(record a,record b)
{
	return a.number<b.number;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(b,0,sizeof(b));
		cot.clear();
		int n,k;
		cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			cot.insert(a[i]);
			b[a[i]]++;
		}
		int len=cot.size();
		int j=1;
		for(auto it=cot.begin();it!=cot.end();it++)
		{
			c[j].content=*it;
			c[j].number=b[*it];
			j++;
		}
		sort(c+1,c+1+len,compare);
		bool flag=0;
		int cnt=0;
		for(int i=1;i<=len;i++)
		{
			cnt+=c[i].number;
			if(cnt>=k)
			{
				if(cnt==k)
					cnt=len-i;
				else
					cnt=len-i+1;
				flag=1;
				break;
			}
		}
		if(!flag)
			cnt=1;
		else
		{
			if(cnt==0)
				cout<<1<<endl;
			else
				cout<<cnt<<endl;
		}
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
int a[100005],b[100005];
//map<int,int>b;
set<int>cot;
struct record
{
	int content;
	int number;
}c[100005];
int compare(record a,record b)
{
	return a.number<b.number;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(b,0,sizeof(b));
		cot.clear();
		int n,k;
		cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			cot.insert(a[i]);
			b[a[i]]++;
		}
		int len=cot.size();
		int j=1;
		for(auto it=cot.begin();it!=cot.end();it++)
		{
			c[j].content=*it;
			c[j].number=b[*it];
			j++;
		}
		sort(c+1,c+1+len,compare);
		bool flag=0;
		int cnt=0;
		for(int i=1;i<=len;i++)
		{
			cnt+=c[i].number;
			if(cnt>=k)
			{
				if(cnt==k)
					cnt=len-i;
				else
					cnt=len-i+1;
				flag=1;
				break;
			}
		}
		if(!flag)
			cnt=1;
		else
		{
			if(cnt==0)
				cout<<1<<endl;
			else
				cout<<cnt<<endl;
		}
	}
	return 0;
}

Submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[100005];
int main() {
	int t; cin >> t;
	while (t--) {
		memset(a, 0, sizeof(a));
		int n, k; cin >> n >> k;
		int x;
		int mmax = 0;
		for (int i = 1; i <= n; i++) {
			cin >> x;
			a[x]++;
			//cout << x << " " << a[x] << endl;
			mmax = max(mmax, x);
		}
		if (k >= n) {
			cout << "1" << endl;
			continue;
		}
		int cnt = 0;
		//cout << mmax << endl;
		sort(a + 1, a + 1 + mmax, greater<int>());
		for (int i = mmax; i >= 1; i--) {
			if (a[i] != 0) {
				//cout << a[i] << endl;
				if (a[i] <= k) {
					k -= a[i];
				}
				else {
					cnt++;
				}
			}
		}
		if (cnt == 0) {
			cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[100005];
int main() {
	int t; cin >> t;
	while (t--) {
		memset(a, 0, sizeof(a));
		int n, k; cin >> n >> k;
		int x;
		int mmax = 0;
		for (int i = 1; i <= n; i++) {
			cin >> x;
			a[x]++;
			//cout << x << " " << a[x] << endl;
			mmax = max(mmax, x);
		}
		if (k >= n) {
			cout << "1" << endl;
			continue;
		}
		int cnt = 0;
		//cout << mmax << endl;
		sort(a + 1, a + 1 + mmax, greater<int>());
		for (int i = mmax; i >= 1; i--) {
			if (a[i] != 0) {
				//cout << a[i] << endl;
				if (a[i] <= k) {
					k -= a[i];
				}
				else {
					cnt++;
				}
			}
		}
		if (cnt == 0) {
			cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

Submission (verdict: Accepted):
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		vector<ll>a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a.begin(),a.end());
		vector<ll>w={1};//用于计数 
		for(int i=1;i<n;i++){
			if(a[i]==a[i-1]){
				w.back()++;
			}
			else{
				w.push_back(1);
			}
		}
		sort(w.begin(),w.end());
		int len=w.size();
		bool f=false;
		for (int i = 0; i <len - 1; i++) {
        if (w[i] > k) {
            cout << len- i <<endl;
            f=true;
            break;
        }
        k -= w[i];}
       if(!f) cout<<1<<endl;
	}
	return 0;	
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define rec(i, a, b) for(int i=a; i<b; ++i)
#define forn(i,n) rec(i, 0, n)
#define rrange(d) d.rbegin(), d.rend() 
#define range(d) d.begin(), d.end()
#define f first
#define s second
#define test freopen("../input.in", "r", stdin);
#define nl cout<<"\n";
#define ws <<" "<<
#define bf cout << endl;
#define tm(x) (int)x.size()
#define printv(V) for(auto v:V) cout << v << ' ';
#define bit(MASK,BIT) (MASK & (1<<(BIT)))

using namespace std;
typedef long long ll;
const int mod = 1e7+9;

void bini(int n){
	for(int i = 31; i>=0; i--){
		if(bit(n, i)) cout << 1;
		else cout << 0;
	}
}

void solve(){
	int l, r; cin >> l >> r;
	
	int m = 0;
	
	int lbit = 0, rbit = 0;
	
	for(int i=31; i>=0; i--){
		if(bit(r,i) && bit(l,i)){
			m |= (1 << i);
		}
		if(bit(r,i) && !bit(l,i)){
			rbit = i;
			break;
		}
	}
	
	for(int i=rbit-1; i>=0; i--){
		if(bit(l,i)){
			lbit = i;
			break;
		}
	}
	//cout << lbit ws rbit;nl;
	
	for(int i=lbit; i<rbit; i++){
		if(bit(r,i) != bit(l,i)){
			m |= (1 << i);
		}
		else if(bit(l,i) == 0 && bit(r,i) == 0){
			m |= (1 << i);
		}
	}
	
	for(int i=lbit-1; i>=0; i--){
		if(bit(l,i) == 0 && bit(r,i) == 0){
			m |= (1 << i);
		}		
	}
	
	if(m < l){
		m |= (1 << rbit);
	}
	//cout << "L "; bini(l);nl;
	//cout << "m "; bini(m);nl;
	//cout << "R "; bini(r);nl;
	
	cout << l ws m ws r;nl;
	
	//cout << (l^m) + (m^r) + (l^r);nl;
	
}


int main()
{
	cin.tie(nullptr)->sync_with_stdio(false);
	//test
	int t; cin >> t; while(t--)
	solve();

	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define rec(i, a, b) for(int i=a; i<b; ++i)
#define forn(i,n) rec(i, 0, n)
#define rrange(d) d.rbegin(), d.rend() 
#define range(d) d.begin(), d.end()
#define f first
#define s second
#define test freopen("../input.in", "r", stdin);
#define nl cout<<"\n";
#define ws <<" "<<
#define bf cout << endl;
#define tm(x) (int)x.size()
#define printv(V) for(auto v:V) cout << v << ' ';
#define bit(MASK,BIT) (MASK & (1<<(BIT)))

using namespace std;
typedef long long ll;
const int mod = 1e7+9;

void bini(int n){
	for(int i = 31; i>=0; i--){
		if(bit(n, i)) cout << 1;
		else cout << 0;
	}
}

void solve(){
	int l, r; cin >> l >> r;
	
	int m = 0;
	
	int lbit = 0, rbit = 0;
	
	for(int i=31; i>=0; i--){
		if(bit(r,i) && bit(l,i)){
			m |= (1 << i);
		}
		if(bit(r,i) && !bit(l,i)){
			rbit = i;
			break;
		}
	}
	
	for(int i=rbit-1; i>=0; i--){
		if(bit(l,i)){
			lbit = i;
			break;
		}
	}
	//cout << lbit ws rbit;nl;
	
	for(int i=lbit; i<rbit; i++){
		if(bit(r,i) != bit(l,i)){
			m |= (1 << i);
		}
		else if(bit(l,i) == 0 && bit(r,i) == 0){
			m |= (1 << i);
		}
	}
	
	for(int i=lbit-1; i>=0; i--){
		if(bit(l,i) == 0 && bit(r,i) == 0){
			m |= (1 << i);
		}		
	}
	
	if(m < l){
		m |= (1 << rbit);
	}
	//cout << "L "; bini(l);nl;
	//cout << "m "; bini(m);nl;
	//cout << "R "; bini(r);nl;
	
	cout << l ws m ws r;nl;
	
	//cout << (l^m) + (m^r) + (l^r);nl;
	
}


int main()
{
	cin.tie(nullptr)->sync_with_stdio(false);
	//test
	int t; cin >> t; while(t--)
	solve();

	return 0;
}




Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int l, r;
		cin >> l >> r;
		int k = 31 - __builtin_clz(l ^ r);
		int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
		cout << a << " " << b << " " << c << endl;
	}
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int l, r;
		cin >> l >> r;
		int k = 31 - __builtin_clz(l ^ r);
		int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
		cout << a << " " << b << " " << c << endl;
	}
	return 0;
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define Fast_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long int
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

/* ***********  My code start here *********** */

int32_t main()
{
    Fast_IO

#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    clock_t danger_close = clock();

    int t;
    cin >> t;
    while (t--)
    {
        int l, r, x, y, z;
        cin >> l >> r;
        int k = 31 - __builtin_clz(l^r);
        x = l | 1 << k;
        y = x-1;
        if(x == r)
            z = l;
        else
            z = r;
        cout << x << " " << y << " " << z << endl;

    }
    debug("Total Time: %.3f\n", (double)(clock() - danger_close) / CLOCKS_PER_SEC);
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


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



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d;

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d;

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}

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



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d[x];

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d;

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}

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



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d;

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d[x];

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

}

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



using namespace std;



int main(){

    int t;

    cin>>t;

    while(t--){

        int x;

        cin>>x;

        vector<int>d(x);

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

            cin>>d[i];

        }

        int v=1;

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

            if(d[i]>d[i+1]){

                v=0;

                break;

            }

            else{

                int c=d[i];

                d[i]=0;

                d[i+1]=d[i+1]-c;

            }

        }

        if(v){

            cout<<"Yes"<<endl;

        }else{

            cout<<"No"<<endl;

        }

    }

    

    

    return 0;

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

Previous submission (verdict: Wrong answer on test 2):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < min(r - l + 1, l); i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < min(n, 2*r - l + 1); i++){
		right.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());
	sort(right.begin(), right.end());
	
	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	sum = accumulate(middle.begin(), middle.end(), 0ll);
	for(int i = 0; i < min(right.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += right[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < l; i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < n; i++){
		right.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());
	sort(right.begin(), right.end());
	
	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	sum = accumulate(middle.begin(), middle.end(), 0ll);
	for(int i = 0; i < min(right.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += right[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < l; i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < n; i++){
		right.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());
	sort(right.begin(), right.end());
	
	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	sum = accumulate(middle.begin(), middle.end(), 0ll);
	for(int i = 0; i < min(right.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += right[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Wrong answer on test 2):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < l; i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < n; i++){
		left.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());

	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < min(r - l + 1, l); i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < min(n, 2*r - l + 1); i++){
		right.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());
	sort(right.begin(), right.end());
	
	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	sum = accumulate(middle.begin(), middle.end(), 0ll);
	for(int i = 0; i < min(right.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += right[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < l; i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < n; i++){
		left.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());

	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Submission (verdict: Accepted):
// Problem: B. Subsequence Update
// Contest: Codeforces - Codeforces Round 1000 (Div. 2)
// URL: https://codeforces.com/contest/2063/problem/B
// Memory Limit: 256 MB
// Time Limit: 1500 ms

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

#define int long long
#define endl '\n'


void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	vector<int>a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<int>left, right, middle;
	for(int i = 0; i < l - 1; i++){
		left.push_back(a[i]);
	}
	for(int i = r; i < n; i++){
		right.push_back(a[i]);
	}
	for(int i = l - 1; i < r; i++){
		middle.push_back(a[i]);
	}
	
	sort(left.begin(), left.end());
	sort(middle.rbegin(), middle.rend());
	sort(right.begin(), right.end());
	
	int ans = accumulate(middle.begin(), middle.end(), 0ll), sum = ans;
	for(int i = 0; i < min(left.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += left[i];
		ans = min(ans, sum);	
	}
	sum = accumulate(middle.begin(), middle.end(), 0ll);
	for(int i = 0; i < min(right.size(), middle.size()); i++){	
		sum -= middle[i];
		sum += right[i];
		ans = min(ans, sum);	
	}
	
	cout << ans << endl;
}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr); std::cout.tie(nullptr);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}