ShaysXIA/CodeInsightBench huggingface dataset:
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);

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

            cin >> v[i];

        }

        l--;

      

        vector<int> u(v.begin() + l, v.end());

        sort(v.begin(), v.begin()+r);

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



        long long sum_w = accumulate(v.begin(), v.begin() + r-l , 0);

        long long sum_u = accumulate(u.begin(), u.begin() + r - l, 0);



        cout << min(sum_w, sum_u) << endl;

    }

    return 0;

}



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

using namespace std;



int main() {

    int t, n, l, r, i, a[200000];

    cin >> t;

    while (t--) {

        cin >> n >> l >> r;

        l--; // Convert to 0-based index

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

            cin >> a[i];

        }

        vector<int> c(a + l, a + n);

        sort(a, a + r);

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

        cout << min(accumulate(a, a + r - l, 0ll), accumulate(c.begin(), c.begin() + r - l, 0ll)) << ' ';

    }

}



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

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

using namespace std;

typedef long long ll;

const int N=100005;

ll a[N],b[N],c[N];

void solve(){

    ll n,l,r;cin>>n>>l>>r;

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

        cin>>a[i];

        b[i]=a[i],c[i]=a[i];

    }

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

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

    ll ans1=0,ans2=0;

    for(int i=1;i<=r-l+1;i++) ans1+=b[i];

    for(int i=l;i<=r;i++) ans2+=c[i];

    cout<<min(ans1,ans2)<<endl;

}

int main()

{

    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int T;cin>>T;

    while(T--){

        solve();

    }

    return 0;

}



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

using namespace std;

typedef long long ll;

const int N=100005;

ll a[N],b[N],c[N];

void solve(){

    ll n,l,r;cin>>n>>l>>r;

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

        cin>>a[i];

        b[i]=a[i],c[i]=a[i];

    }

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

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

    ll ans1=0,ans2=0;

    for(int i=1;i<=r-l+1;i++) ans1+=b[i];

    for(int i=l;i<=r;i++) ans2+=c[i];

    cout<<min(ans1,ans2)<<endl;

}

int main()

{

    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int T;cin>>T;

    while(T--){

        solve();

    }

    return 0;

}



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

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

using namespace std;

#define int long long

const int N=1e5+7;



int q[N],ql[N],qr[N];



void slove(){

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

//	vector<int>q(n+5);

	

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

	cin>>q[i];

	ql[i]=q[i];

	qr[i]=q[i];	

	}



	

	sort(ql,ql+r+1);

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

		

	int ans=0,num=r-l+1;

	int cntl=0,cntr=0;

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

		cntl+=ql[i];

	

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

	cntr+=qr[i];

	

	ans=min(cntl,cntr);

	

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

    cout<<ans<<'\n';

}



signed main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int t=1; 

	cin>>t;

   

	while(t--){

		slove();

	}  

  

}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+7;

int q[N],ql[N],qr[N];

void slove(){
	int n,l,r;  cin>>n>>l>>r;
//	vector<int>q(n+5);
	
	for(int i=1;i<=n;i++){
	cin>>q[i];
	ql[i]=q[i];
	qr[i]=q[i];	
	}

	
	sort(ql,ql+1+r);
	sort(qr+l,qr+1+n);
		
	int ans=0,num=r-l+1;
	int cntl=0,cntr=0;
	for(int i=1;i<=num;i++){
		cntl+=ql[i];
		cntr+=qr[i];
	}
	ans=min(cntl,cntr);
	
//	for(int i=1;i<=n;i++)
    cout<<ans<<'\n';
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1; 
	cin>>t;
   
	while(t--){
		slove();
	}  
  
}

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

Code 1:
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,l,r,x;
		ll y=0;
		int a[100000];
		cin>>n>>l>>r;
		x=r-l+1;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		sort(a+1,a+n+1);
		for(int i=1;i<=x;i++)
		{
			y+=a[i];
		}
		cout<<y<<endl;
	}
	return 0;
}

Code 2:
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
//int main()
//{
//	int t;
//	cin>>t;
//	while(t--)
//	{
//		int n,l,r,x;
//		ll y=0;
//		int a[100000];
//		cin>>n>>l>>r;
//		x=r-l+1;
//		for(int i=1;i<=n;i++)
//		{
//			cin>>a[i];
//		}
//		sort(a+1,a+n+1);
//		for(int i=1;i<=x;i++)
//		{
//			y+=a[i];
//		}
//		cout<<y<<endl;
//	}
//	return 0;
//}
//只能一次反转
void solve()
{
	int n,l,r;
	cin>>n>>l>>r;
	ll res=0;
	vector<int>a(n+1);
	for(int i=1;i<=n;i++)
		cin>>a[i];
	priority_queue<int> tmpl_ans,tmpr_ans;
	//tmpl_ans 和 tmpr_ans 是最大堆，用于存储区间 [l, r] 内的元素。
    priority_queue<int,vector<int>,greater<int>> lans,rans;
	//lans 和 rans 是最小堆，分别用于存储区间 [1, l-1] 和 [r+1, n] 的元素。
	for(int i=l;i<=r;i++)
	{
		res+=a[i];
		tmpl_ans.push(a[i]);
		tmpr_ans.push(a[i]);
	}
	for(int i=1;i<l;i++)
		lans.push(a[i]);
	for(int i=r+1;i<=n;i++)
		rans.push(a[i]);
	
	ll res1=res;
	
  while (!lans.empty()){
    int now1 = tmpl_ans.top(),now2 = lans.top();
    if (now1>now2){
      res -= now1-now2;
      tmpl_ans.pop();
      tmpl_ans.push(now2);
      lans.pop();
    }else{
      break;
    }
  }
  while (!rans.empty()){
    int now1 = tmpr_ans.top(),now2 = rans.top();//最大元素
    if (now1>now2){
      res1 -= now1-now2;
      tmpr_ans.pop();//移除堆顶的最大元素
      tmpr_ans.push(now2);//将新的较小元素 now2 插入堆中
      rans.pop();
    }else{
      break;
    }
  }
  cout<<min(res1,res)<<endl;
}
 
int main()
{
	int t;
	cin>>t;
    while (t--) 
	{
		solve();
	}
	return 0;
}


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

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

using namespace std;
using vi = vector<int>;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--;
    
    vi arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    
    vi brr = arr;
    sort(brr.begin() + l, brr.end());
    
    vi crr = arr;
    sort(crr.begin(), crr.begin() + r, greater<int>());
    
    int sum_brr = 0, sum_crr = 0;
    for (int i = l; i < r; ++i) {
        sum_brr += brr[i];
        sum_crr += crr[i];
    }
    
    cout << min(sum_brr, sum_crr) << "\n";
}

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

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


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

using namespace std;
using vi = vector<int>;
using ll = long long;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--;
    
    vi arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    
    vi brr = arr;
    sort(brr.begin() + l, brr.end());
    
    vi crr = arr;
    sort(crr.begin(), crr.begin() + r, greater<int>());
    
    ll sum_brr = accumulate(brr.begin() + l, brr.begin() + r, 0LL);
    ll sum_crr = accumulate(crr.begin() + l, crr.begin() + r, 0LL);
    
    cout << min(sum_brr, sum_crr) << "\n";
}

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

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

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

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

using namespace std;





void solve() {

    int n, l, r;

    cin >> n >> l >> r;



    l--;

    r--;

    vector<long long> a(n);

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

    int size = r - l + 1;

    vector<long long> first(a.begin(), a.begin() + r + 1);

    vector<long long> second(a.begin() + l, a.end());



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



    long long res =  LONG_LONG_MAX;

    long long sum = 0;

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

        sum += first[i];

    }



    res = min(sum, res);



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

    sum = 0;



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

        sum += second[i];

    }



    res = min(sum, res);



    cout << res << endl;

}



int main() {

    // freopen("../input.txt", "r", stdin);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}



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

using namespace std;





void solve() {

    int n, l, r;

    cin >> n >> l >> r;



    l--;

    r--;

    vector<long long> a(n);

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

    int size = r - l + 1;

    vector first(a.begin(), a.begin() + r + 1);

    vector second(a.begin() + l, a.end());



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



    long long res =  INT_MAX;

    long long sum = 0;

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

        sum += first[i];

    }



    res = min(sum, res);



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

    sum = 0;



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

        sum += second[i];

    }



    res = min(sum, res);



    cout << res << endl;

}



int main() {

    // freopen("../input.txt", "r", stdin);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }

}



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

Code 1:
/******************************************************************************



                              Online C++ Compiler.

               Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.



*******************************************************************************/



#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

int main()

{

    int t;

    cin>>t;

    

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vector<int>v(n);

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

            cin >> v[i];

        }

        

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

        int total = r-l+1;

        int answer = 0;

        int i = 0;

        while(total--){

            answer += v[i++];

        }

        cout<<answer<<endl;

    }



    return 0;

}

Code 2:
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>v(n);
        for(int i = 0;i<n;i++){
            cin >> v[i];
        }
        
        long long leftSum = 0;
        long long rightSum = 0;
        vector<int>left;
        vector<int>right;
        
        for(int i = 0;i<r;i++){
            left.push_back(v[i]);
        }
        for(int i = l-1;i<n;i++){
            right.push_back(v[i]);
        }
    
        
        sort(left.begin(),left.end());
        sort(right.begin(),right.end());
        
        for(int i = 0;i<r-l+1;i++){
            leftSum += left[i];
            rightSum += right[i];
        }
        
        cout<<min(leftSum,rightSum)<<endl;
        
    }

    return 0;
}

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

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
void solve(ll tc)
{
    ll n,l,r,i,s1=0,s2=0,a,p;
    cin>>n>>l>>r;
    p=r-l+1;
    vector<ll>v1,v2;
    for(i=0; i<n; i++)
    {
        cin>>a;
        if(i<r) v1.pb(a);
        if(i>=l-1) v2.pb(a);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    for(i=0; i<p; i++) s1+=v1[i],s2+=v2[i];
    ll s=min(s1,s2);
    cout<<s<<endl;




}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc=1;
    cin>>tc;
    for(ll i=1; i<=tc; i++)
    {
        solve(i);
    }
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(ll tc)
{
ll n,l,r,i,s=0,p;
cin>>n>>l>>r;
p=r-l+1;
vector<ll>v(n);
for(i=0;i<n;i++) cin>>v[i];
sort(v.begin(),v.end());
for(i=0;i<p;i++) s+=v[i];
cout<<s<<endl;




}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc=1;
    cin>>tc;
    for(ll i=1; i<=tc; i++)
    {
        solve(i);
    }
}


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

Code 1:
#include <iostream>

#include <algorithm>

#include <cstring>

#define ll long long

const int N = 1e5 + 8;



using namespace std;



int a[N];



void solve() {

    memset(a , sizeof a, 0);

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

    

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

    

    auto b = a;

    

    ll sum1 = 0, sum2 = 0;

    

    sort(a , a + r);

    

    for (int i = 0 ; i < r - l + 1; i ++) sum1 += a[i];

    

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

    

    for (int i = l - 1 ; i < l - 1 + r - l + 1; i ++) sum2 +=b[i];

    

    ll ans = min(sum1, sum2);

    

    cout << ans << endl;

    

    

}





int main(void) {

    ios::sync_with_stdio(false);cin.tie(nullptr);

    int t ; cin >> t;

    while (t--)solve();

    

}

Code 2:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define ll long long
const int N = 1e5 + 8;

using namespace std;



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


int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int t ; cin >> t;
    while (t--)solve();
    
}

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

Code 1:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w1[110000],w2[110000];
void solve(){
    ll n,l,r;
    cin>>n>>l>>r;
    for(int i=0;i<n;i++){
        cin>>w1[i];
        w2[i]=w1[i];
    }
    ll x1=0,x2=0;
    sort(w1,w1+r,greater<ll>());
    sort(w2+l-1,w2+n);
    for(int i=l-1;i<r;i++){
        x1+=w1[i];
        x2+=w2[i];
    }
    cout<<min(x1,x2)<<'\n';
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    ll t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
};

Code 2:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w[110000];
void solve(){
    ll n,l,r;
    cin>>n>>l>>r;
    for(int i=0;i<n;i++)  cin>>w[i];
    sort(w,w+r,greater<ll>());
    sort(w+l-1,w+n);
    ll x=0;
    for(int i=l-1;i<r;i++)  x+=w[i];
    cout<<x<<'\n';
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
    ll 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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42;
#define endl '\n'
#endif

#define int long long

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

    vector<int>a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    vector<int>b(a.begin(), a.begin() + r);
    vector<int>c(a.begin() + l - 1, a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    // debug(l, r, a, b, c)
    return min(accumulate(b.begin(), b.begin() + (r - l + 1), 0), accumulate(c.begin(), c.begin() + (r - l + 1), 0));
}
signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int _ = 1;
    cin >> _;
    while (_--) {
        cout << solve(_) << endl;
    }
}


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

using namespace std;

#ifdef LOCAL

#include "debug.h"

#else

#define debug(...) 42;

#define endl '\n'

#endif



#define int long long



int solve(int _) {

    int l, r, n;

    cin >> n >> l >> r;



    vector<int>a(n);

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

        cin >> a[i];

    }



    vector<int>b(a.begin(), a.begin() + r);

    vector<int>c(a.begin() + l - 1, a.end());

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

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



    // debug(l, r, a, b, c)

    return min(accumulate(b.begin(), b.begin() + (r - l + 1), 0ll), accumulate(c.begin(), c.begin() + (r - l + 1), 0ll));

}

signed main()

{

    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int _ = 1;

    cin >> _;

    while (_--) {

        cout << solve(_) << endl;

    }

}



Answer: 2
Problem: 2063B - Subsequence Update
Language: python

Code 1:
t=int(input())

for case in range(t):

    s=0

    n,l,r=map(int,input().split())

    seq=list(map(int,input().split()))

    a=seq[:l-1]+sorted(seq[l-1:])

    b=sorted(seq[:r])[::-1]+seq[r:]

    print(min(sum(a[l-1:r]),sum(b[l-1:r])))

Code 2:
t=int(input())

for case in range(t):

    s=0

    n,l,r=map(int,input().split())

    seq=list(map(int,input().split()))

    seg=list(seq[l-1:r])

    exseg=list(seq[:l-1])

    exseg.extend(list(seq[r:]))

    seg.append(0)

    s=sum(seg)

    if len(exseg)!=0:

        while min(exseg)<max(seg):

            a=min(exseg)

            b=max(seg)

            s=s-b+a

            seg.remove(b)

            exseg.remove(a)

            if len(exseg)==0:

                break

    print(s)

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (ll)(v).size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i, a, b) for (ll i = (a); i < (b); i++)
#define fr(i, a, b) for (ll i = (a); i >= (b); i--)
void solve() {
    ll n,l,r;
    cin>>n>>l>>r;
    vll a(n);
    f(i,0,n){cin>>a[i];}
    vll fr;vll b;
    f(i,0,l-1)
    {
      fr.pb(a[i]);
    }
    vll crr;
    f(i,l-1,r)
    {
      crr.pb(a[i]);
    }
    f(i,r,n)
    {
      b.pb(a[i]);
    }
    sort(all(crr));
    sort(all(fr));sort(all(b));
    ll x1=0;
    if(fr.size()>0)
    {
      for(int i=crr.size()-1;i>=0;i--)
      {
        if(x1==fr.size()){break;}
        if(fr[x1]<crr[i])
        {
          crr[i]=fr[x1];x1++;continue;
        }
        if(fr[x1]>crr[i]){break;}
      }
    }
    sort(all(crr));x1=0;
    if(b.size()>0)
    {
      for(int i=crr.size()-1;i>=0;i--)
      {
        if(x1==b.size()){break;}
        if(b[x1]<crr[i])
        {
          crr[i]=b[x1];x1++;continue;
        }
        if(b[x1]>crr[i]){break;}
      }
    }
    ll ans=0;
    f(i,0,crr.size())
    {
      ans+=crr[i];
    }
    cout<<ans<<endl;
    
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t; cin >> t;
    while (t--) { solve(); }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (ll)(v).size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i, a, b) for (ll i = (a); i < (b); i++)
#define fr(i, a, b) for (ll i = (a); i >= (b); i--)
void solve() {
    ll n,l,r;
    cin>>n>>l>>r;
    vll a(n);
    f(i,0,n){cin>>a[i];}
    vll fr;vll b;
    f(i,0,l-1)
    {
      fr.pb(a[i]);
    }
    vll crr;
    f(i,l-1,r)
    {
      crr.pb(a[i]);
    }
    f(i,r,n)
    {
      b.pb(a[i]);
    }
    vll tou=crr;ll a1=0;ll a2=a1;
    sort(all(crr));
    sort(all(fr));sort(all(b));
    ll x1=0;
    if(fr.size()>0)
    {
      for(int i=crr.size()-1;i>=0;i--)
      {
        if(x1==fr.size()){break;}
        if(fr[x1]<crr[i])
        {
          crr[i]=fr[x1];x1++;continue;
        }
        if(fr[x1]>crr[i]){break;}
      }
    }
    f(i,0,crr.size())
    {
      a1+=crr[i];
    }
    crr=tou;
    sort(all(crr));x1=0;
    if(b.size()>0)
    {
      for(int i=crr.size()-1;i>=0;i--)
      {
        if(x1==b.size()){break;}
        if(b[x1]<crr[i])
        {
          crr[i]=b[x1];x1++;continue;
        }
        if(b[x1]>crr[i]){break;}
      }
    }
    
    f(i,0,crr.size())
    {
      a2+=crr[i];
    }
    cout<<min(a1,a2)<<endl;
    
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t; cin >> t;
    while (t--) { solve(); }
    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-->0){
        long long int n,l,r;
        cin>>n>>l>>r;
        vector<long long int>v(n);
        vector<long long int>a,b;
        long long int g=(r-l)+1;
        for(long long int i=0;i<n;i++){
            cin>>v[i];
        }
        for(long long int i=l-1;i<n;i++){
            a.push_back(v[i]);
        }
        for(long long int i=0;i<r;i++){
            b.push_back(v[i]);
        }
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        long long int ans1=0;
        long long int ans2=0;
        long long int ans=0;
        for(int i=0;i<g;i++){
            ans1+=(a[i]);
        }
        for(int i=0;i<g;i++){
            ans2+=(b[i]);
        }
        cout<<min(ans1,ans2)<<endl;
    }
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t-->0){
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>v(n);
        vector<int>a,b;
        int g=(r-l)+1;
        for(int i=0;i<n;i++){
            cin>>v[i];
        }
        for(int i=l-1;i<n;i++){
            a.push_back(v[i]);
        }
        for(int i=0;i<r;i++){
            b.push_back(v[i]);
        }
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        int ans1=0;
        int ans2=0;
        int ans=0;
        for(int i=0;i<g;i++){
            ans1+=(a[i]);
        }
        for(int i=0;i<g;i++){
            ans2+=(b[i]);
        }
        cout<<min(ans1,ans2)<<endl;
    }
}

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

Code 1:
#include <iostream>

#include <numeric>

#include <algorithm>

#include <vector>

#include <ranges>



int main()

{

    std::size_t tc, n, l, r;

    std::cin >> tc;

    for(std::size_t i{0}; i<tc; ++i)

    {

        std::cin >> n >> l >> r;

        std::vector<unsigned long long> seq(n);

        for(auto& el : seq) 

            std::cin >> el;

        std::vector<unsigned long long> left(seq.begin(), seq.begin()+r),

        right(seq.begin()+l-1, seq.end());

        std::ranges::sort(left);

        std::ranges::sort(right);

        std::cout << std::min(std::accumulate(left.begin(), left.begin()+r-l+1, 0ULL), 

                     std::accumulate(right.begin(), right.begin()+r-l+1, 0ULL)) << "\n";

    }

}

Code 2:
#include <iostream>

#include <numeric>

#include <algorithm>

#include <vector>

#include <ranges>



int main()

{

    std::size_t tc, n, l, r;

    std::cin >> tc;

    for(std::size_t i{0}; i<tc; ++i)

    {

        std::cin >> n >> l >> r;

        std::vector<unsigned long long> seq(n);

        for(auto& el : seq) 

            std::cin >> el;

        std::vector<unsigned long long> left(seq.begin(), seq.begin()+r),

        right(seq.begin()+l-1, seq.end());

        std::ranges::sort(left);

        std::ranges::sort(right);

        

        std::cout << std::min(std::accumulate(left.begin(), left.begin()+r-l+1, 0), 

                     std::accumulate(right.begin(), right.begin()+r-l+1, 0)) << "\n";

    }

}

Answer: 1