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

Solution 1 (runtime: 187 ms):
#include <bits/stdc++.h>



using namespace std;



int main()

{

    int t;

    cin>>t;

    while(t--)

    {

        int n,l,r;

        cin>>n>>l>>r;

        vector<long long>a(n);

        for(auto &x:a)

            cin>>x;

        long long sum=0;

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

        {

            sum+=a[i];

        }

        if(r<n && l>1)

        {

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

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

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

            long long lsum=sum,rsum=sum;

            int xl=r,yl=r-1;

            while(xl<n && yl>=l-1 && a[xl]<a[yl])

            {

                lsum=lsum-a[yl]+a[xl];

                xl++;

                yl--;

            }

            int xr=0,yr=r-1;

            while(xr<l-1 && yr>=l-1 && a[xr]<a[yr]) 

            {

                rsum=rsum-a[yr]+a[xr];

                xr++;

                yr--;

            }

            sum=min(lsum,rsum);

            cout<<sum;

        }

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

        {

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

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

            int x=r,y=r-1;

            while(x<n && y>=0 && a[x]<a[y])

            {

                sum=sum-a[y]+a[x];

                x++;

                y--;

            }

            cout<<sum;

        }

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

        {

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

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

            int x=0,y=r-1;

            while(x<l-1 && y >=l-1 && a[x]<a[y])

            {

                sum=sum-a[y]+a[x];

                x++;

                y--;

            }

            cout<<sum;

        }

        else

        {

            cout<<sum;

        }

        cout<<"\n";

    }

}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>



#define ll long long int

#define ull unsigned long long int

using namespace std;



void solve()

{

    ll n, l, r;

    cin >> n >> l >> r;



    vector<ll> arr(n + 1);

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

        cin >> arr[i];

    }

    

    sort((arr.begin() + l), (arr.begin() + r + 1));

    sort(arr.begin(), (arr.begin() + l));

    sort((arr.begin() + r + 1), (arr.end()));



    ll indx = r;

    ll cnt = 0;

    ll target = r - l + 1;

    ll ansf = 0, anss = 0;

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

        if (arr[i] < arr[indx]) {

            ansf += arr[i];

            cnt++;

            indx--;

        }

        else break;

        if (cnt == target) break;

    }

    ll k = l;

    while (cnt != target) {

        cnt++;

        ansf += arr[k];

        k++;

    }



    cnt = 0;

    indx = r;

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

        if (arr[i] <= arr[indx]) {

            anss += arr[i];

            cnt++;

            indx--;

        }

        else break;

        if (cnt == target) break;

    }

    k = l;

    while (cnt != target) {

        cnt++;

        anss += arr[k];

        k++;

    }



    cout << min(ansf, anss) << '\n';

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    #ifndef ONLINE_JUDGE

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

    freopen("output.txt", "w", stdout);

    #endif



    ll tc;

    cin >> tc;

    while (tc--)

    {

        solve();

    }



    return 0;

}