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

Code 1:
#include <iostream>
#include <algorithm>
#include <cstring>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;

void solve(){
    int n, l, r;
    cin >> n >> l >> r;
    int a[N], b[N];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a + 1, a + 1 + r);
    sort(b + l, b + 1 + n);
    long long res1 = 0, res2 = 0;
    for(int i = 1; i <= r - l + 1; i++){
        res1 += a[i];
    }
    for(int i = l; i <= r; i++){
        res2 += b[i];
    }
    cout << min(res1, res2);
}

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

Code 2:
#include <iostream>
#include <algorithm>
#include <cstring>
#define endl '\n'
using namespace std;
const int N = 1e5 + 10;

void solve(){
    int n, l, r;
    cin >> n >> l >> r;
    int a[N], b[N];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(a + 1, a + 1 + r);
    sort(b + l, b + 1 + n);
    long long res1 = 0, res2 = 0;
    for(int i = 1; i <= r - l + 1; i++){
        res1 += a[i];
    }
    for(int i = l; i <= r; i++){
        res2 += b[i];
    }
    cout << min(res1, res2) << endl;
}

int main(){
    ios::sync_with_stdio(false); 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;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a;
    for(int i = 0; i < n; i++) {
        int u;
        cin >> u;
        a.push_back(u);
    }

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

    int sum1 = 0, sum2 = 0, sum3 = 0;
    int k1 = 0, k2 = r - 1, k3 = r;
    int change; 

    while(k1 <= l - 2 && k2 >= l - 1 && a[k1] < a[k2]) {
        sum1 += a[k1++];
        sum2 += a[k2--];
    }

    change = sum2 - sum1;
    k2 = r - 1;
    sum2 = 0;

    while(k3 <= n - 1 && k2 >= l - 1 && a[k3] < a[k2]) {
        sum3 += a[k3++];
        sum2 += a[k2--];
    }

    change = max(change, sum2 - sum3);

    int result = 0;
    for(int i = l - 1; i <= r - 1; i++) {
        result += a[i];
    }
    result -= change;
    cout << result << endl;
}


int main(){
    int t;
    cin >> t;
    while(t > 0) {
        solve();
        t--;
    }
    return 0;
}

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

using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a;
    for(int i = 0; i < n; i++) {
        int u;
        cin >> u;
        a.push_back(u);
    }

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

    long long int sum1 = 0, sum2 = 0, sum3 = 0;
    int k1 = 0, k2 = r - 1, k3 = r;
    long long int change; 

    while(k1 <= l - 2 && k2 >= l - 1 && a[k1] < a[k2]) {
        sum1 += a[k1++];
        sum2 += a[k2--];
    }

    change = sum2 - sum1;
    k2 = r - 1;
    sum2 = 0;

    while(k3 <= n - 1 && k2 >= l - 1 && a[k3] < a[k2]) {
        sum3 += a[k3++];
        sum2 += a[k2--];
    }

    change = max(change, sum2 - sum3);

    long long int result = 0;
    for(int i = l - 1; i <= r - 1; i++) {
        result += a[i];
    }
    result -= change;
    cout << result << endl;
}


int main(){
    int t;
    cin >> t;
    while(t > 0) {
        solve();
        t--;
    }
    return 0;
}

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

Code 1:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class SubsequenceUpdate {
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int tests = Integer.parseInt(scanner.nextLine());
    while (tests > 0){
      int n = scanner.nextInt();
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      long[] arr = new long[n];
      for (int i = 0; i < arr.length; i++){
        arr[i] = scanner.nextLong();
      }

      ArrayList<Long> toL = new ArrayList<>();
      ArrayList<Long> toR = new ArrayList<>();
      for (int i = 0; i < r; i++){
        toR.add(arr[i]);
      }
      for (int i = l - 1; i < n; i++){
        toL.add(arr[i]);
      }

      Collections.sort(toL);
      Collections.sort(toR);

      long sumOne = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumOne += toL.get(i);
      }

      long sumTwo = 0;
      for (int i = 0; i < r - l + 1; i++){
        sumTwo += toR.get(i);
      }

      System.out.println(Math.min(sumTwo, sumOne));
      tests--;
    }
  }
}


Code 2:
import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;



public class SubsequenceUpdate {

  public static void main(String[] args){

    Scanner scanner = new Scanner(System.in);

    int tests = Integer.parseInt(scanner.nextLine());

    while (tests > 0){

      int n = scanner.nextInt();

      int l = scanner.nextInt();

      int r = scanner.nextInt();

      long[] arr = new long[n];

      for (int i = 0; i < arr.length; i++){

        arr[i] = scanner.nextLong();

      }



      ArrayList<Long> toL = new ArrayList<>();

      ArrayList<Long> toR = new ArrayList<>();

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

        toR.add(arr[i]);

      }

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

        toL.add(arr[i]);

      }



      Collections.sort(toL);

      Collections.sort(toR);



      int sumOne = 0;

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

        sumOne += toL.get(i);

      }



      int sumTwo = 0;

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

        sumTwo += toR.get(i);

      }



      System.out.println(Math.min(sumTwo, sumOne));

      tests--;

    }

  }

}



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

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

#define ll long long int
#define ld long double
#define ek ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void init()
{
     
}

void solve() {
    ll n, l, r;
    cin >> n >> l >> r;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<ll> b,c,d;
    ll sum=0;
    for(ll i=l-1;i<r;i++) {
        b.push_back(a[i]);
        sum+=a[i];
    }
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    for(ll i=0;i<l-1;i++) {
        c.push_back(a[i]);
    }
    for(ll i=r;i<n;i++) {
        d.push_back(a[i]);
    }
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    ll ans=sum;
    for(ll i=0;i<min(b.size(), c.size());i++) {
        if(b[i]>c[i]) {
            ans+=(c[i]-b[i]); 
        }
    }
    ll ans1=sum;
    for(ll i=0;i<min(b.size(), d.size());i++) {
        if(b[i]>d[i]) {
            ans1+=(d[i]-b[i]);
        }
    }
    cout<<min({sum,ans, ans1})<<endl;

    
}

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    ek;
    ll t = 1;
    cin >> t;
    init();
    while(t--)
    {
        solve();
    }
    return 0;
}

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

#define ll long long int
#define ld long double
#define ek ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void init()
{
     
}

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

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    ek;
    ll t = 1;
    cin >> t;
    init();
    while(t--)
    {
        solve();
    }
    return 0;
}

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

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

using namespace std;



#define ll long long

#define mod 1000000007

#define rr(i, n) for (int i = 0; i < n; i++)

#define pb push_back

#define all(v) v.begin(), v.end()

#define nn '\n'



// Fast Input-Output

void fastIO()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

}



int main()

{

    fastIO();



    int t;

    cin >> t;

    while (t--)

    {

        int n, l, r;

        cin >> n >> l >> r;

        vector<int> a(n);

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

        {

            cin >> a[i];

        }



        vector<int> before, after, btw;

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

        {

            if (i < l - 1)

                before.pb(a[i]);

            else if (i > r - 1)

                after.pb(a[i]);

            else

                btw.pb(a[i]);

        }



        sort(all(before));

        sort(all(after));

        sort(all(btw));



        int sum = accumulate(all(btw), 0);

        int mini = sum;



        int i = 0, j = btw.size() - 1;

        while (i < before.size() && j >= 0 && before[i] < btw[j])

        {

            sum = sum - btw[j] + before[i];

            mini = min(mini, sum);

            i++;

            j--;

        }



        sum = accumulate(all(btw), 0);



        i = 0, j = btw.size() - 1;

        while (i < after.size() && j >= 0 && after[i] < btw[j])

        {

            sum = sum - btw[j] + after[i];

            mini = min(mini, sum);

            i++;

            j--;

        }



        cout << mini << nn;

    }



    return 0;

}



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

#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        int n, l, r;
        cin >> n >> l >> r;
        l--; // Adjust for 0-based index

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

        vector<ll> brr = arr;
        sort(brr.begin() + l, brr.end());

        vector<ll> crr = arr;
        sort(crr.begin(), crr.begin() + r, greater<ll>());

        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) << nn;
    }

    return 0;
}


Answer: 2
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 pb push_back

#define INF 1e18

#define yes cout << "YES" << endl;

#define no cout << "NO" << endl;

#define F first

#define S second

#define sz(x) x.size()

#define all(x) x.begin(), x.end()

#define rall(x) (x).rbegin(), (x).rend()

#define gcd(a, b) __gcd(a, b)

#define lcm(a, b) ((a) * ((b) / gcd(a, b)))

#define MAX3(a, b, c) max(a, max(b, c))

#define MIN3(a, b, c) min(a, min(b, c))

#define vi vector<ll>

#define vvi vector<vector<ll>>

#define pii pair<ll, ll>

#define vii vector<pair<ll, ll>>

void solve()

{

    ll n, l, r;

    cin >> n >> l >> r;

    vector<ll> v(n);

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

    {

        cin >> v[i];

    }

    sort(all(v));

    vi p(n, 0);

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

    {

        if (i == 0)

        {

            p[i] = v[i];

        }

        else

        {

            p[i] = p[i - 1] + v[i];

        }

    }

    ll dif = r - l + 1;

    cout << p[dif - 1] << endl;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    int t;

    cin >> t;

    while (t--)

        solve();

    return 0;

}

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

using namespace std;

#define ll long long

#define ull unsigned long long

#define pb push_back

#define INF 1e18

#define yes cout << "YES" << endl;

#define no cout << "NO" << endl;

#define F first

#define S second

#define sz(x) x.size()

#define all(x) x.begin(), x.end()

#define rall(x) (x).rbegin(), (x).rend()

#define gcd(a, b) __gcd(a, b)

#define lcm(a, b) ((a) * ((b) / gcd(a, b)))

#define MAX3(a, b, c) max(a, max(b, c))

#define MIN3(a, b, c) min(a, min(b, c))

#define vi vector<ll>

#define vvi vector<vector<ll>>

#define pii pair<ll, ll>

#define vii vector<pair<ll, ll>>

void solve()

{

    ll n, l, r;

    cin >> n >> l >> r;

    l--;

    r--;

    vector<ll> v(n);

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

    {

        cin >> v[i];

    }

    vi f, b;

    for (ll i = 0; i <= r; i++)

    {

        f.pb(v[i]);

    }

    for (ll i = l; i < n; i++)

    {

        b.pb(v[i]);

    }

    sort(all(f));

    sort(all(b));



    ll sum1 = accumulate(f.begin(), f.begin() + (int)(r - l + 1), 0LL);

    ll sum2 = accumulate(b.begin(), b.begin() + (int)(r - l + 1), 0LL);

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

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

    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 ll = long long;

using ull = unsigned long long;

#define endl "\n";



void solve()

{

    int k;

    cin >> k;



    int l,r;

    cin>>l>>r;



    int len=r-l+1;



    vector<ll>a;

    vector<ll>b(len);

    vector<ll>c;



    int m=0,n=0;

    ll sum1=0,sum2=0;

    int len1=0,len2=0;

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

    {

        if(i+1>=l&&i+1<=r)

        {

            cin>>b[n];

            sum1+=b[n];

            n++;

        }

        else if(i+1<l)

        {

            int num;

            cin>>num;

            a.push_back(num);

            len1++;

        }

        else if(i+1>r)

        {

            int num2;

            cin>>num2;

            c.push_back(num2);

            len2++;

        }

    }

    sum2=sum1;



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

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

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



    for(int i=0;i<min(len,len1);i++)

    {

        if(a[i]<b[len-1-i])

        {

            sum1-=b[len-1-i];

            sum1+=a[i];

        }

    }

    for(int i=0;i<min(len,len2);i++)

    {

        if(c[i]<b[len-1-i])

        {

            sum2-=b[len-1-i];

            sum2+=c[i];

        }

    }



    cout<<min(sum1,sum2)<<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;
using ll = long long;
using ull = unsigned long long;
#define endl "\n";

void solve()
{
    int k;
    cin >> k;

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

    int len=r-l+1;

    vector<ll>a(k-len);
    vector<ll>b(len);

    int m=0,n=0;
    ll sum1=0,sum2=0;
    for(int i=0;i<k;i++)
    {
        if(i+1>=l&&i+1<=r)
        {
            cin>>b[n];
            sum2+=b[n];
            n++;
        }
        else
        {
            cin>>a[m];
            sum1+=a[m];
            m++;
        }
    }

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

    for(int i=0;i<min(len,k-len);i++)
    {
        if(a[i]<b[len-1-i])
        {
            sum2-=b[len-1-i];
            sum2+=a[i];
        }
    }

    cout<<sum2<<endl;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t;
    cin >> t;

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

    return 0;
}

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

Code 1:
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define int long long
#define PII pair<int, int> 
#define _rep(i,a,b) for( int i=(a); i<=(b); ++i)
#define _per(i,a,b) for( int i=(a); i>=(b); --i)
using namespace std;
const int N = 1e6+10 ;
const int M = 1e3+10 ;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7  ;
const double eps = 1e-9 ;
int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }
int lcm(int a, int b){ return a * b / gcd(a,b); } 
int qmi(int a, int b){
    int res = 1 ;
    while(b){
        if(b&1) res = a * res % MOD ;
        b >>= 1 ;
        a = a * a % MOD ;
    }
    return res ;
}
int T = 1 ;
int ans = 0 ;
int n , m, k, q ;
int a[N] ;
void solve(){
    int l, r ;
    cin >> n >> l >> r ;
    for(int i = 1; i <= n ; ++ i){
        cin >> a[i] ;
    }
    vector<int> vec1 ;
    vector<int> vec2 ;
    for(int i = 1; i <= n ; ++ i){
        if(i <= r) vec1.push_back(a[i]) ;
        if(i >=l ) vec2.push_back(a[i]) ;
    }
    sort(vec1.begin(), vec1.end()) ;
    sort(vec2.begin(), vec2.end()) ;
    int ans1 = 0 ;
    int ans2 = 0 ;
    for(int i = 0 ; i < r - l + 1; ++ i){
        ans1 += vec1[i] ;
        ans2 += vec2[i] ;
    }
    ans = min(ans1, ans2) ;
    cout << ans << endl ;
}
signed main(){
    IOS ;
    cin >> T ;
    while(T --){
        solve() ;
    }
    return 0;
    
}

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

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

#define endl '\n'

#define int long long

#define PII pair<int, int> 

#define _rep(i,a,b) for( int i=(a); i<=(b); ++i)

#define _per(i,a,b) for( int i=(a); i>=(b); --i)

using namespace std;

const int N = 1e6+10 ;

const int M = 1e3+10 ;

const int INF = 0x3f3f3f3f3f3f3f3f;

const int MOD = 1e9 + 7  ;

const double eps = 1e-9 ;

int gcd(int a, int b){ return b == 0 ? a : gcd(b, a%b); }

int lcm(int a, int b){ return a * b / gcd(a,b); } 

int qmi(int a, int b){

    int res = 1 ;

    while(b){

        if(b&1) res = a * res % MOD ;

        b >>= 1 ;

        a = a * a % MOD ;

    }

    return res ;

}

int T = 1 ;

int ans = 0 ;

int n , m, k, q ;

int a[N] ;

void solve(){

    int l, r ;

    cin >> n >> l >> r ;

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

        cin >> a[i] ;

    }

    ans = 0 ;

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

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

        ans += a[i] ;

    }

    cout << ans << endl ;



}

signed main(){

    IOS ;

    cin >> T ;

    while(T --){

        solve() ;

    }

    return 0;

    

}

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

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

void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	int a[n+1];
	for(int i=0;i<n;i++) cin >> a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<=r-l;i++) ans+=a[i];
	cout << ans << endl;
	
}

signed main(){
	int t; cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

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

bool cmp(int a,int b){
	return a>b;
}

void solve(){
	int n,l,r;
	cin >> n >> l >> r;
	int a[n+1];
	vector<int> v1,v2,v3;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		if(i<=l-1) v1.push_back(a[i]);
		else if(i>=l&&i<=r) v2.push_back(a[i]),sum+=a[i];
		else v3.push_back(a[i]);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end(),cmp);
	sort(v3.begin(),v3.end());
	
	int sum1=sum,sum2=sum;
	for(int i=0;i<min(v2.size(),v1.size());i++){
		if(v1[i]<v2[i]) sum1-=(v2[i]-v1[i]);
	}
	for(int i=0;i<min(v2.size(),v3.size());i++){
		if(v3[i]<v2[i]) sum2-=(v2[i]-v3[i]);
	}
	cout << min(sum1,sum2) << endl;
	
}

signed main(){
	int t; cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

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

Code 1:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        l--;
        r--;
        vector<ll> a(n);
        vector<ll> v;

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

       for(int i=r;i>=l;i--){
        v.push_back(a[i]);
        a.erase(a.begin()+i);
       }
       
       ll ma=0;
       ll mi=0;
       ll x=0;
       while(1){
         mi=*min_element(a.begin(),a.end());
         ma=*max_element(v.begin(),v.end());
          if(ma<=mi) break;
          if(a.empty() || v.empty()) break;
         v.push_back(mi);
         a.push_back(ma);
         v.erase(find(v.begin(),v.end(),ma));
         a.erase(find(a.begin(),a.end(),mi));
         
        
       }

       ll sum=0;
       sum=accumulate(v.begin(),v.end(),0LL);

       cout<<sum<<endl;

    }
}

Code 2:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


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

        vector<ll> lft;
        vector<ll> rht;
        
       for(int i=0;i<=r;i++){
        lft.push_back(a[i]);
       }
       
       for(int i=l;i<n;i++){
        rht.push_back(a[i]);
       }

       sort(lft.begin(),lft.end());
       sort(rht.begin(),rht.end());
       ll suml=0,sumr=0;
       for(int i=0;i<(r-l+1);i++){
         suml+=lft[i];
         sumr+=rht[i];
       }

       ll sum=min(suml,sumr);
       cout<<sum<<endl;
    }
}

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

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

using namespace std;

#define int long long

#define endl '\n'

#define pii pair<int, int>

#define IOS                       \

    ios_base::sync_with_stdio(0); \

    cin.tie(0);                   \

    cout.tie(0);

constexpr int N = 5e5 + 10;

constexpr int mod = 1e9 + 7;

constexpr int inf = 0x3f3f3f3f;

void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

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

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

        cin >> a[i];

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

    {

        b.push_back(a[i]);

    }

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

    {

        c.push_back(a[i]);

    }

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

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

    int sum1 = 0, sum2 = 0;

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

        sum1 += b[i];

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

        sum2 += c[i];

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

}

signed main()

{

    IOS

    int _ = 1;

    cin >> _;

    while(_ --)

    {

        solve();

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pii pair<int, int>
#define IOS                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
constexpr int N = 5e5 + 10;
constexpr int mod = 1e9 + 7;
constexpr int inf = 0x3f3f3f3f;
void solve()
{
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n);
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int sum = 0;
    for(int i = 0; i <= r - l; i ++)
        sum += a[i];
    cout << sum << endl;
}
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --)
    {
        solve();
    }
    return 0;
}

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

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        long n,l,r,s1,s2;
        s1=s2=0;
        cin >> n >> l >> r;
        vector<long> a(n),a1,a2;
        for (int i=0;i<n;i++)
        cin >> a[i];
        for (int i=0;i<r;i++)
        a1.push_back(a[i]);
        for (int i=l-1;i<n;i++)
        a2.push_back(a[i]);

        sort(a1.begin(),a1.end());
        sort(a2.begin(),a2.end());

        for (int i=0;i<r-l+1;i++)
        s1+=a1[i];
        for (int i=0;i<r-l+1;i++)
        s2+=a2[i];

        s1 = min(s1,s2);
        cout << s1 << "\n";
    }
}

Answer: 1