ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define ull unsigned long long

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

#define PII pair<int, int>

#define PLL pair<ll, ll>

#define lowbit(x) (x & -(x))

#define INF 0x3f3f3f3f

#define ls(p) p << 1

#define rs(p) p << 1 | 1

const double eps = 1e-6;

const double PI = acos(double(-1));

const ull base = 131;

const double C = 0.5772156649;

const int mod = 1000007;

const int N = 1e5 + 7;

ll a[N],b[N];

void solve(){

    int n, l, r;

    cin >> n >> l >> r;

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

        cin >> a[i];

        b[i] = a[i];

    }

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

    ll ans = 0;

    for (int i = l; i <= r;i++){

        ans += b[i - l + 1];

    }

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

    ll res = 0;

    for (int i = l; i <= r;i++){

        res += a[i];

    }

    ans = min(ans, res);

    cout << ans << endl;

}

int main()

{

    IOS;

    int t=1;

    cin>>t;

    while(t--){

        solve();

    }

    return 0;

}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n" 
#define ull unsigned long long
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define lowbit(x) (x & -(x))
#define INF 0x3f3f3f3f
#define ls(p) p << 1
#define rs(p) p << 1 | 1
const double eps = 1e-6;
const double PI = acos(double(-1));
const ull base = 131;
const double C = 0.5772156649;
const int mod = 1000007;
const int N = 2e5 + 7;
int w[N];
void solve()
{
    int n, q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> w[i];
    }
    
}
int main()
{
    IOS;
    int t = 1;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 1
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define FORI(sti, n) for(int i=(sti); i<(n); i++)
#define FORJ(stj, n) for(int j=(stj); j<(n); j++)
#define FORK(stk, n) for(int k=(stk); k<(n); k++)
#define tvi(v) FORI(0, (v).size()) cerr << (v)[i] << " "; cerr << "\n";
#define tii(val) cerr <<  "(" << (val).first << ", " << (val).second << ")\n";
#define tvii(v) FORI(0, (v).size()) { tii((v)[i]) } cerr << "\n";
#define tvvi(v) FORI(0, (v).size()) { FORJ(0, (v)[i].size()){ cerr <<  v[i][j] << " "; } cerr << "\n"; }  
#define all(v) (v).begin(), (v).end() 
#define rall(v) (v).rbegin(), (v).rend() 

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vbl;

void solve(){
	int n, l, r;
	cin >> n >> l >> r;
	vi v(n);
	for(auto &a: v) cin >> a;

	vi store, numbers;

	for(int i=0; i<n; i++){
		if(i>=(l-1) && i<=(r-1)){
			store.pb(v[i]);
		}
		else{
			numbers.pb(v[i]);
		}
	}
	sort(rall(store));
	sort(all(numbers));

	int ans=0, idx=0;	
	for(int i=0; i<store.size(); i++){
		if(idx<numbers.size() && store[i]>numbers[idx]){
			store[i]=numbers[idx];
			idx++;
		}
		ans+=store[i];
	}

	cout << ans << "\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	
	int t; cin >> t; while(t--)
		solve();

    return 0;
}


Code 2:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define FORI(sti, n) for(int i=(sti); i<(n); i++)
#define FORJ(stj, n) for(int j=(stj); j<(n); j++)
#define FORK(stk, n) for(int k=(stk); k<(n); k++)
#define tvi(v) FORI(0, (v).size()) cerr << (v)[i] << " "; cerr << "\n";
#define tii(val) cerr <<  "(" << (val).first << ", " << (val).second << ")\n";
#define tvii(v) FORI(0, (v).size()) { tii((v)[i]) } cerr << "\n";
#define tvvi(v) FORI(0, (v).size()) { FORJ(0, (v)[i].size()){ cerr <<  v[i][j] << " "; } cerr << "\n"; }  
#define all(v) (v).begin(), (v).end() 
#define rall(v) (v).rbegin(), (v).rend() 

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vbl;



void solve(){
	int n, l, r;
	cin >> n >> l >> r;
	vi v(n);
	for(auto &a: v) cin >> a;

	vi store, numbers, pt1, pt2;
	int npt1=0;
	int npt2=0;

	for(int i=0; i<n; i++){
		if(i>=(l-1) && i<=(r-1)){
			store.pb(v[i]);
		}
		else{
			if(i<(l-1)){ 
				pt1.pb(v[i]); npt1+=v[i]; 
			}
			else{ 
				pt2.pb(v[i]); npt2+=v[i]; 
			}
		}
	}
	
	sort(rall(store));
	vi store2 = store;
	sort(all(pt1));
	sort(all(pt2));

	int ans1=0, ans2=0, idx1=0, idx2=0;	
	for(int i=0; i<store.size(); i++){
		if(idx1<pt1.size() && store[i]>pt1[idx1]){
			store[i]=pt1[idx1];
			idx1++;
		}

		if(idx2<pt2.size() && store2[i]>pt2[idx2]){
			store2[i]=pt2[idx2];
			idx2++;
		}

		ans1+=store[i];
		ans2+=store2[i];
	}

	cout << min(ans1, ans2) << "\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	
	int t; cin >> t; while(t--)
		solve();

    return 0;
}


Answer: 2
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include<iostream>

#include<algorithm>

using namespace std;

int main()

{

   int t;

   cin>>t;

   while(t--)

   {

    int n,l,r;

    cin>>n>>l>>r;

    int a[n];

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

        cin>>a[i];



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

    sort(a,a+l-1);

    sort(a+r,a+n);





    int start = 0 , mid = r-1 , end = r;



    int long long  ans_1 = 0 ,  ans_2 = 0;



    while(mid>=l-1)

    {

        if(start<l-1)

            ans_1+=min(a[start],a[mid]);

        else

            ans_1+=a[mid];

        if(end<n)

            ans_2+=min(a[end],a[mid]);

        else

            ans_2+=a[mid];

        

        start++;

        mid--;

        end++;



    }



    cout<<min(ans_1,ans_2)<<endl;

   }

}

Code 2:
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        int a[n];
        for(int i = 0 ; i < n ; i++)
            cin>>a[i];
        int x = r-l+1;
        int lim[x];
        int rem[n-x];
        int e = 0 , f = 0 ;

        for(int i = 0 ; i < n ; i++)
        {
            if(i+1>=l and i+1<=r)
            {
                lim[e] = a[i];
                e++;
            }

            else
            {
                rem[f] = a[i];
                f++;
            }
        }

        sort(lim,lim+x);
        sort(rem,rem+(n-x));

        int p = x-1 , q = 0;

        int res = 0 ;

        while(p>=0 and q<n-x)
        {

            res+=min(lim[p],rem[q]);
            p--;
            q++;
        }

        if(q>=n-x)
        {
            while(p>=0)
                res+=lim[p--];
        }

        cout<<res<<endl;

    }
}

Answer: 1
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include<iostream>

#include <cmath>

#include <bits/stdc++.h>

using namespace std;

int main(){

    int t;

    cin>>t;

    vector<int> ans;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        long long sum=0;

        vector<int> vec(n,0);

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

            cin>>vec[i];

        }

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

        for(int i=0;i<=(r-l);i++){

            sum+=vec[i];

        }

        ans.push_back(sum);

    }

    for(auto num:ans) cout<<num<<endl;

    return 0;

}



Code 2:
#include<iostream>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    vector<long long> ans;
    while(t--){
        int n,l,r,x;
        cin>>n>>l>>r;
        vector<int> vec(n,0);
        vector<int> help(n,0);
        for(int i=0;i<n;i++){
            cin>>x;
            vec[i]=x;
            help[i]=x;
        }
        sort(vec.begin(), vec.begin()+r);
        sort(help.begin()+(l-1), help.end());
        int i=0, j=l-1;
        long long sum1=0, sum2=0;
        while(i<=(r-l)) sum1+=vec[i++];
        while(j<r) sum2+=help[j++];
        ans.push_back(min(sum1, sum2));
        
    }
    for(auto num:ans) cout<<num<<endl;
    return 0;
}


Answer: 2
Problem: 2063B - Subsequence Update
Language: c++17 

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

 
int main(){

    int t;
    cin >> t;

    while(t--){
        int n,l,r;
        cin >> n >> l >>r;
        vector<int> v(n, 0);
        for (int i = 0; i < n;i++){ 
        cin >> v[i];
        }
        vector<int> v2 = v;
        vector<int> v3 = v;
        sort(v2.begin(), v2.begin() + r );
        sort(v3.begin() +l-1, v3.end()  );
        long long sum1 = 0;
        for (int i = 0; i < (r - l + 1);i++){
            sum1 += v2[i];
        }
        long long sum2 = 0;
        for (int i = l-1; i < r;i++){
            sum2 += v3[i];
        }

        cout << min(sum1,sum2) << endl;
    }
}

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

 
int main(){

    int t;
    cin >> t;

    while(t--){
        int n,l,r;
        cin >> n >> l >>r;
        vector<int> v(n, 0);
        for (int i = 0; i < n;i++){ 
        cin >> v[i];
        }
        vector<int> v2 = v;
        vector<int> v3 = v;
        sort(v2.begin(), v2.begin() + (r+1) );
        sort(v3.begin() +l-1, v3.end()  );
        int sum1 = 0;
        for (int i = 0; i < (r - l + 1);i++){
            sum1 += v2[i];
        }
        int sum2 = 0;
        for (int i = l-1; i < r;i++){
            sum2 += v3[i];
        }

        cout << min(sum1,sum2) << endl;
    }
}

Answer: 1
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t, n, l, r;
    cin >> t;
    for (int i = 0; i < t; i++) {
        vector<int> lArr, rArr;
        cin >> n >> l >> r;
        for (int j = 1; j <= n; j++) {
            int a;
            cin >> a;
            if (j <= r) lArr.push_back(a);
            if (j >= l) rArr.push_back(a);
        }

        sort(lArr.begin(), lArr.end());
        sort(rArr.begin(), rArr.end());
        long long max1 = 0, max2 = 0;

        for (int k = 0; k < r - l + 1; k++) {
            max1 = (max1 + lArr[k] < 0) ? LLONG_MAX : max1 + lArr[k];
            max2 = (max2 + rArr[k] < 0) ? LLONG_MAX : max2 + rArr[k];
        }
        cout << min(max1, max2) << "\n";
    }
}


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int t, n, l, r;
    cin >> t;
    for (int i = 0; i < t; i++) {
        vector<int> lArr, rArr;
        cin >> n >> l >> r;
        for (int j = 1; j <= n; j++) {
            int a;
            cin >> a;
            if (j <= r) lArr.push_back(a);
            if (j >= l) rArr.push_back(a);
        }

        sort(lArr.begin(), lArr.end());
        sort(rArr.begin(), rArr.end());
        int max1 = 0, max2 = 0;

        for (int k = 0; k < r - l + 1; k++) {
            max1 += lArr[k];
            max2 += rArr[k];
        }
        cout << min(max1, max2) << "\n";
    }
}


Answer: 1
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
/**

 *  author: xing huan liu kong 

 *  created: 2025-02-13 10:22:59

 *  

 *  即使这个图论(world)大的无边无际

 *  我也会深度优先搜索(dfs)找到你..

**/

#include <bits/stdc++.h>

#define ll long long

#define endl '\n'  

#define point(x) fixed<<setprecision(x)

using namespace std;



#define int long long

typedef pair<int, int> PII;

typedef array<int, 3> arr;



void solve()

{

    int n, l, r;

    cin >> n >> l >> r;



    vector<int> a(n + 1, 0), b, c, d;

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

        cin >> a[i];

        if (i < l) b.push_back(a[i]);

        else if (i > r) c.push_back(a[i]);

        else d.push_back(a[i]);

    }



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

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

    sort(d.rbegin(), d.rend());



    int sum = accumulate(d.begin(), d.end(), 0ll);

    int res = sum;

    for (int i = 0, ts = 0; i < (int)b.size() && i < (int)d.size(); i ++ ) {

        ts += b[i] - d[i];

        res = min (res, sum + ts);

    }

    for (int i = 0, ts = 0; i < (int)c.size() && i < (int)d.size(); i ++ ) {

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

        res = min (res, sum + ts);

    }



    cout << res << endl;



}



signed main(void)

{

    ios_base::sync_with_stdio(0);

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

    

    int t = 1;

    cin >> t;



    while(t -- ){

        solve();

    }



    return 0;

}

Code 2:
/**
 *  author: xing huan liu kong 
 *  created: 2025-02-13 10:22:59
 *  
 *  即使这个图论(world)大的无边无际
 *  我也会深度优先搜索(dfs)找到你..
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'  
#define point(x) fixed<<setprecision(x)
using namespace std;

#define int long long
typedef pair<int, int> PII;
typedef array<int, 3> arr;

void solve()
{
    int n, l, r;
    cin >> n >> l >> r;

    vector<int> a(n + 1, 0), b, c, d;
    for (int i = 1; i <= n; i ++ ) {
        cin >> a[i];
        if (i < l) b.push_back(a[i]);
        else if (i > r) c.push_back(a[i]);
        else d.push_back(a[i]);
    }

    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    sort(d.rbegin(), d.rend());

    int sum = accumulate(d.begin(), d.end(), 0);
    int res = sum;
    for (int i = 0, ts = 0; i < (int)b.size() && i < (int)d.size(); i ++ ) {
        ts += b[i] - d[i];
        res = min (res, sum + ts);
    }
    for (int i = 0, ts = 0; i < (int)c.size() && i < (int)d.size(); i ++ ) {
        ts += c[i] - d[i];
        res = min (res, sum + ts);
    }

    cout << res << endl;

}

signed main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;

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

    return 0;
}

Answer: 1
Problem: 2063B - Subsequence Update
Language: c++17 

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


#define endl '\n'
typedef long long ll;

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

	while(t-- >0){
	

		ll s,l,r;
		cin>>s>>l>>r;
		vector<ll> vec(s);
		for(auto &x: vec){cin>>x;}	
		vector<ll> pref = vec;
		ll prefix=0;
		sort(pref.begin(),pref.begin()+r);

		reverse(pref.begin(),pref.begin()+r);
		prefix+= accumulate(pref.begin()+l-1,pref.begin()+r,0);
		
		vector<ll> suffix = vec;
		ll suff=0;
		sort(suffix.begin()+l-1,suffix.end());

		suff=accumulate(suffix.begin()+l-1,suffix.begin()+r,0);
		cout<<min(prefix,suff)<<endl;

	}


// 9 2 3 4 5 2 5 1 5









	return 0;
}


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


#define endl '\n'
typedef long long ll;

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

	while(t-- >0){
	

		ll s,l,r;
		cin>>s>>l>>r;
		vector<ll> vec(s);
		for(auto &x: vec){cin>>x;}	
		vector<ll> pref = vec;
		ll prefix=0;
		sort(pref.begin(),pref.begin()+r);

		reverse(pref.begin(),pref.begin()+r);
		for(int i = l-1;i<r;i++){
			prefix+=pref[i];
		}
		vector<ll> suffix = vec;
		ll suff=0;
		sort(suffix.begin()+l-1,suffix.end());

		for(int i = l-1;i<r;i++){
			suff+=suffix[i];
		}
		cout<<min(prefix,suff)<<endl;

	}


	return 0;
}


Answer: 2
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
#define int long long

int INF = 1e18;
const int N = 5e5+20;

int n,l,r;
int lis[N];

void solve() {
    cin>>n>>l>>r;
    for(int i = 0;i<n;i++) cin>>lis[i];
    sort(lis,lis+n);

    int ans = 0;
    for(int i = 0;i<r-l+1;i++) ans += lis[i];
    cout<<ans<<endl;

}

signed main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout<<fixed<<setprecision(9);

    int caset = 1;
    cin >> caset;
    while (caset--) { solve(); }


    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
#define int long long

int INF = 1e18;
const int N = 5e5+20;

int n,l,r;
int lis[N];
vector<int> nl,nr,in;

void solve() {
    cin>>n>>l>>r;
    for(int i = 1;i<=n;i++) cin>>lis[i];

    nl.clear();
    nr.clear();
    in.clear();

    for(int i = 1;i<l;i++) nl.push_back(lis[i]);
    for(int i = l;i<=r;i++) in.push_back(lis[i]);
    for(int i = r+1;i<=n;i++) nr.push_back(lis[i]);

    sort(nl.begin(),nl.end());
    sort(in.begin(),in.end(),greater<int>());
    sort(nr.begin(),nr.end());

    int t1 = 0;
    int t2 = 0;
    for(int i = 0;i<in.size();i++){
        if(i < nl.size()) t1 += min(nl[i],in[i]);
        else t1 += in[i];

        if(i < nr.size()) t2 += min(nr[i],in[i]);
        else t2 += in[i];
    }

    cout<<min(t1,t2)<<endl;
    

}

signed main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout<<fixed<<setprecision(9);

    int caset = 1;
    cin >> caset;
    while (caset--) { solve(); }


    return 0;
}

Answer: 2
Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// Function to solve the problem
int solve(int n, vector<int> sequence, int l, int r) {
    vector<int> copy = sequence;
    sort(copy.begin(), copy.begin() + r,greater<int>());
    sort(sequence.begin() + (l - 1), sequence.end());
    int left = 0, right = 0;
    for (int i = l - 1; i < r; i++) {
        left += copy[i];
        right += sequence[i];
    }
    return min(left, right);
}

int main() {
    int t;
    cin >> t;
    
    while (t-- > 0) {
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> sequence(n);
        
        for (int i = 0; i < n; i++) {
            cin >> sequence[i];
        }
        
        cout << solve(n, sequence, l, r) << endl;
    }

    return 0;
}


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// Function to solve the problem
long long solve(int n, vector<int> sequence, int l, int r) {
    vector<int> copy = sequence;
    
    // Sorting first 'r' elements in descending order
    sort(copy.begin(), copy.begin() + r, greater<int>());
    
    // Sorting from 'l' to 'n' in ascending order
    sort(sequence.begin() + (l - 1), sequence.end());
    
    long long left = 0, right = 0; // Use long long to store large sums
    
    for (int i = l - 1; i < r; i++) {
        left += copy[i];
        right += sequence[i];
    }
    
    return min(left, right);
}

int main() {
    int t;
    cin >> t;
    
    while (t-- > 0) {
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> sequence(n);
        
        for (int i = 0; i < n; i++) {
            cin >> sequence[i];
        }
        
        cout << solve(n, sequence, l, r) << endl;
    }

    return 0;
}

//#include <iostream>
//#include <vector>
//#include <algorithm>
//
//using namespace std;
//int solve(int n, vector<int>& sequence, int l, int r) {
//    vector<int> left_part(sequence.begin(), sequence.begin() + r);
//    vector<int> right_part(sequence.begin() + (l - 1), sequence.end());
//    sort(left_part.begin(), left_part.end(), greater<int>());
//    sort(right_part.begin(), right_part.end()); // Ascending
//
//    int left_sum = 0, right_sum = 0;
//    for (int i = l - 1; i < r; i++) {
//        left_sum += left_part[i];
//        right_sum += right_part[i - (l - 1)];
//    }
//
//    return min(left_sum, right_sum);
//}
//
//int main() {
//    int t;
//    cin >> t;
//    
//    while (t-- > 0) {
//        int n, l, r;
//        cin >> n >> l >> r;
//        vector<int> sequence(n);
//        
//        for (int i = 0; i < n; i++) {
//            cin >> sequence[i];
//        }
//        
//        cout << solve(n, sequence, l, r) << endl;
//    }
//
//    return 0;
//}


Answer: 2
Problem: 2063B - Subsequence Update
Language: c++23 

Code 1:
#include <bits/stdc++.h>



using namespace std;



const int N = 100010;

int a[N],b[N];

int main(){

    int t; scanf("%d",&t);

    while(t--){

        int n,l,r,len; scanf("%d%d%d",&n,&l,&r);

        len = r - l + 1;

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

            scanf("%d",&a[i]);

            b[i] = a[i];

        }

        sort(a,a + r);

        int ans = 0,tmp = 0;

        for(int i = 0;i < len;i++) tmp += a[i];

        sort(b + l - 1,b + n);

        for(int i = l - 1;i < l - 1 + len;i++) ans += b[i];

        ans = min(ans,tmp);

        printf("%d\n",ans);

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;

const int N = 100010;
int a[N],b[N];
int main(){
    int t; scanf("%d",&t);
    while(t--){
        int n,l,r,len; scanf("%d%d%d",&n,&l,&r);
        len = r - l + 1;
        for(int i = 0;i < n;i++){
            scanf("%d",&a[i]);
            b[i] = a[i];
        }
        sort(a,a + r);
        long long ans = 0,tmp = 0;
        for(int i = 0;i < len;i++) tmp += a[i];
        sort(b + l - 1,b + n);
        for(int i = l - 1;i < l - 1 + len;i++) ans += b[i];
        ans = min(ans,tmp);
        printf("%lld\n",ans);
    }
    return 0;
}

Answer: 2
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
#include <bits/stdc++.h>

using namespace std;



void solve()

{

    int n, l, r; cin >> n >> l >> r;

    vector<int> a(n), b(n);

    for(int i=0; i<n; i++) cin >> a[i], b[i]=a[i];

    sort(a.begin(), a.begin()+r-1);

    sort(b.begin()+l-1, b.end());

    cout << min(accumulate(a.begin(), a.begin()+r-l+1, 0ll), accumulate(b.begin()+l-1, b.begin()+r, 0ll)) << '\n';

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int tc=1; cin >> tc;

    while(tc--) solve();

}

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

void solve()
{
    int n, l, r; cin >> n >> l >> r;
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++) cin >> a[i], b[i]=a[i];
    sort(a.begin(), a.begin()+r);
    sort(b.begin()+l-1, b.end());
    cout << min(accumulate(a.begin(), a.begin()+r-l+1, 0ll), accumulate(b.begin()+l-1, b.begin()+r, 0ll)) << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc=1; cin >> tc;
    while(tc--) solve();
}

Answer: 2
Problem: 2063B - Subsequence Update
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pp make_pair
#define endl "\n"
#define f first
#define s second
#define TxtIO   freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define int long long
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t ;cin>>t;
    while (t--)
    {
        int n,l,r ; cin>>n>>l>>r;
        l--;r--;
        vector<int> v(n);
        for (int i = 0 ; i<n ; i++) cin>>v[i];
        sort(v.begin(),v.end());
         int ans=0;
        for (int i = 0;i<r-l+1;i++) ans+=v[i];
        cout<<ans<<endl;
    }
}
// store the indexes
// 3  6  6  4  3 2
// 8 11 11  10 - -
//  after sorting  2 3 3 4 6 6


Code 2:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pp make_pair
#define endl "\n"
#define f first
#define s second
#define TxtIO   freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define int long long

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t ;cin>>t;
    while (t--)
    {
        int n,l,r ; cin>>n>>l>>r;
        l--;r--;
        vector<int> v(n); 
        for (int i = 0 ; i<n ; i++) cin>>v[i];

        vector<int> v1;
        vector<int> v2;
        
        for (int i = l; i<=r;i++) {
        v1.push_back(v[i]);
        v2.push_back(v[i]);
        }

        for (int i = 0 ;i<l;i++) v1.push_back(v[i]);
        for (int i = r+1 ;i<n;i++) v2.push_back(v[i]);

        sort(v1.begin(),v1.end());
        sort(v2.begin(),v2.end());
        int k= r-l+1;
        int sum1=0;
      //  cout<<v1.size()<<" "<<v2.size();
    //    return 0;
        for (int i = 0 ;i<k;i++) sum1+=v1[i];
        
        int sum2 = 0 ;
        for (int i = 0 ; i<k;i++) sum2+=v2[i];
        
        cout<<min(sum1,sum2)<<endl;

    }
}
// store the indexes
// 3  6  6  4  3 2
// 8 11 11  10 - -
//  after sorting  2 3 3 4 6 6

Answer: 2