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

Solution 1 (runtime: 78 ms):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define tt int t; cin >> t; for (int tc=1; tc<=t; tc++)
#define disp(res) cout << "Case " << tc << ": " << (res) << "\n "[tc == t];
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2147483647;
const ll infLL = 9223372036854775807;
const ll MOD = 1000000007LL;



int main() {
    optimize()
    tt {
        int n, l , r;
        cin >> n >> l >> r;
        vector<int> a(n);
        for (int i=0; i<n; i++) {
            cin >> a[i];
        }

        int sz = r-l+1;

        l--, r--;
        
        vector<int> a1, a2, a3;
        for (int i=0; i<l; i++) {
            a1.push_back(a[i]);
        }
        for (int i=l; i<=r; i++) {
            a2.push_back(a[i]);
        }
        for (int i=r+1; i<n; i++) {
            a3.push_back(a[i]);
        }
        vector<int> tem = a2;

        sort(all(a1));
        sort(all(a3));
        
        int cnt = sz;
        for (auto u: a1) {
            if (cnt == 0) break;
            a2.push_back(u);
            cnt--;
        }
        cnt = sz;
        for (auto u: a3) {
            if (cnt == 0) break;
            tem.push_back(u);
            cnt--;
        }

        sort (all(a2));
        sort (all(tem));
        a2.resize(sz);
        tem.resize(sz);

        ll ans1 = 0;
        for (auto u: a2) ans1 += u;
        ll ans2 = 0;
        for (auto u: tem) ans2 += u;

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

    }

    return 0;
}



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

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef long double lld;

 

#define vi vector<ll>

#define py cout << "YES" << endl

#define pn cout << "NO" << endl

#define p(x) cout << x << endl

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

#define rep(x,start,end) for(ll x = start; x < end; x++)

#define rrep(x,start,end) for(ll x = start; x >= end; x--)

#define read(x) rep(i, 0, x.size()) cin >> x[i]

#define parr(arr) rep(i, 0, arr.size()) cout << arr[i] << " "; cout << endl



void solve()

{

    ll n, l, r;

    cin >> n >> l >> r;



    vi a(n+1);

    vi front, back;



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

    {

        cin >> a[i];



        if(i <= r)

        {

            front.push_back(a[i]);

        }

        if(i >= l)

        {

            back.push_back(a[i]);

        }

    } 



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

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



    ll sum1 = 0;

    ll sum2 = 0;



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

    {

        sum1 += front[i];

        sum2 += back[i];

    }



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

}

 

//--------------------------- MAIN -------------------------/

int main() {

    ios_base::sync_with_stdio(false); // to make input output faster

    cin.tie(NULL);



    int t; 

    cin >> t;

    while(t--)

    {

        solve();

    }

    return 0;

}