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

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
#define ull unsigned long long 
#define ld long double
#define ll long long
#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
int mod = 1e9 + 7; 
const int inf = 1e18;
const int N = 1e5 + 50, K = 20;

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

    l--, r--;
    vector<int> a, mid, b;
    int tot = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;

        if(i < l)
            a.push_back(x);
        else if(i > r)  
            b.push_back(x);
        else
            mid.push_back(x), tot += x;
    }

    sort(all(a));
    sort(all(mid), greater<int>());
    sort(all(b));

    int ans1 = 0, ans2 = 0;
    int ans = tot;
    for(int i = 0; i < min(a.size(), mid.size()); i++)
        if(a[i] < mid[i])
            ans -= mid[i], ans += a[i];
    ans1 = ans;

    ans = tot;
    for(int i = 0; i < min(b.size(), mid.size()); i++)
        if(b[i] < mid[i])   
            ans -= mid[i], ans += b[i];

    ans2 = ans;
    cout << min(ans1, ans2) << '\n';
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    cin >> t;
    while(t--)
        solve();
    return 0;
}

Solution 2 (runtime: 93 ms):


// ░░░░░██╗░█████╗░██╗  ░██████╗██╗░░██╗██████╗░███████╗███████╗  ██████╗░░█████╗░███╗░░░███╗

// ░░░░░██║██╔══██╗██║  ██╔════╝██║░░██║██╔══██╗██╔════╝██╔════╝  ██╔══██╗██╔══██╗████╗░████║

// ░░░░░██║███████║██║  ╚█████╗░███████║██████╔╝█████╗░░█████╗░░  ██████╔╝███████║██╔████╔██║

// ██╗░░██║██╔══██║██║  ░╚═══██╗██╔══██║██╔══██╗██╔══╝░░██╔══╝░░  ██╔══██╗██╔══██║██║╚██╔╝██║

// ╚█████╔╝██║░░██║██║  ██████╔╝██║░░██║██║░░██║███████╗███████╗  ██║░░██║██║░░██║██║░╚═╝░██║

// ░╚════╝░╚═╝░░╚═╝╚═╝  ╚═════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚══════╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░░░░╚═╝



#include <iostream>

#include <stdio.h>

#include <math.h>

#include <string.h>

#include <time.h>

#include <stdlib.h>

#include <string>

#include <bitset>

#include <vector>

#include <set>

#include <map>

#include <unordered_map>

#include <queue>

#include <algorithm>

#include <sstream>

#include <stack>

#include <iomanip>

#include <climits>

#include <assert.h>

#include <chrono>



//-----macros-----//



#define ll long long

#define ull unsigned long long

#define ld long double

#define vii vector<ll>

#define pii pair<ll, ll>

#define vvi vector<vii>

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

#define mll map<ll, ll>

#define uml unordered_map<ll, ll>

#define pql priority_queue<ll, vii>

#define pqg priority_queue<ll, vii, greater<ll>>

#define ppi pair<ll, pii>

#define ff first

#define ss second

#define pb push_back

const int d1[4] = {-1, 0, +1, 0};

const int d2[4] = {0, -1, 0, +1};

const char directions[4] = {'U', 'L', 'D', 'R'};

#define mp make_pair

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

#define sz(x) x.size();

#define yn(flag) cout << (flag ? "YES" : "NO") << endl;



using namespace std;



// -------- functions of c++ (not STL of course) -------- //



ll mod = 1e9 + 7;

ll binarySearch(vii v, ll key)

{

    ll low = 0;

    ll high = v.size() - 1;

    while (low <= high)

    {

        ll mid = low + (high - low) / 2;



        if (v[mid] == key)

        {

            return mid;

        }



        if (v[mid] < key)

        {

            low = mid + 1;

        }



        else

        {

            high = mid - 1;

        }

    }

    return -1;

}



bool isPrime(ll n)

{

    if (n <= 1)

    {

        return false;

    }

    if (n <= 3)

    {

        return true;

    }

    if (n % 2 == 0 || n % 3 == 0)

    {

        return false;

    }

    for (ll i = 5; i * i <= n; i = i + 6)

    {

        if (n % i == 0 || n % (i + 2) == 0)

        {

            return false;

        }

    }



    return true;

}



bool isPowerOf2(ll number, int &cnt)

{

    while (number > 1)

    {

        if (number % 2)

        {

            return false;

        }

        cnt++;

        number /= 2;

    }

    return true;

}



vii to_binary(ll number)

{

    vii ans;

    while (number > 0)

    {

        ans.pb(number % 2);

        number /= 2;

    }

    return ans;

}



ll to_decimal(vector<bool> binary)

{

    ll ans = 0;

    reverse(binary.begin(), binary.end());

    ll n = sz(binary);

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

        ans += (binary[i] ? pow(2, i) : 0);

    return ans;

}



vii countFreq(vii v, ll n)

{

    vii count(n, false);

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

    {

        count[v[i]]++;

    }

    return count;

}



vector<bool> ifvis(vii v, ll n)

{

    vector<bool> vis(n, false);



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

    {

        if (vis[v[i]] == true)

        {

            continue;

        }

        else

        {

            vis[v[i]] = true;

        }

    }

    return vis;

}



ll getDivisors(ll n)

{

    vector<ll> divisors;

    for (int i = 2; i * i <= n; ++i)

    {

        if (n % i == 0)

        {

            return i;

            if (i != n / i)

            {

                divisors.push_back(n / i);

            }

        }

    }

    return n;

}



vii suffix_min(vii v, ll n)

{

    vii suffix_mini(n, 0);

    suffix_mini[n - 1] = v[n - 1];

    for (int i = n - 2; i >= 0; i--)

    {

        suffix_mini[i] = min(suffix_mini[i + 1], v[i]);

    }

    return suffix_mini;

}



vii suffix_max(vii v, ll n)

{

    vii suffix_maxi(n, 0);

    suffix_maxi[n - 1] = v[n - 1];

    for (int i = n - 2; i >= 0; i--)

    {

        suffix_maxi[i] = max(suffix_maxi[i + 1], v[i]);

    }

    return suffix_maxi;

}



vii prefix_min(vii v, ll n)

{

    vii prefix_mini(n, 0);

    prefix_mini[0] = v[0];

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

    {

        prefix_mini[i] = min(prefix_mini[i - 1], v[i]);

    }

    return prefix_mini;

}



vii prefix_max(vii v, ll n)

{

    vii prefix_maxi(n, 0);

    prefix_maxi[0] = v[0];

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

    {

        prefix_maxi[i] = max(prefix_maxi[i - 1], v[i]);

    }

    return prefix_maxi;

}



int digitSum(int numberber)

{

    int total = 0;

    while (numberber > 0)

    {

        total += numberber % 10;

        numberber /= 10;

    }

    return total;

}



unordered_map<ll, ll> freqByUMap(vii v, ll size)

{

    unordered_map<ll, ll> freqUMap;



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

    {

        freqUMap[v[i]]++;

    }



    return freqUMap;

}



map<ll, ll> freqByMap(vii v, ll size)

{

    map<ll, ll> freqMap;

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

    {

        freqMap[v[i]]++;

    }



    return freqMap;

}



bool isVowel(char a)

{

    return (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u');

}



ll gcd(ll a, ll b)

{

    while (a > 1 && b > 1)

    {

        if (a > b)

        {

            if (a % b == 0)

            {

                return b;

            }

            a = a % b;

        }

        else

        {

            if (b % a == 0)

            {

                return a;

            }

            b = b % a;

        }

    }

    return 1;

}



ll lcm(ll a, ll b)

{

    return (ll)(a * b) / gcd(a, b);

}



vector<ll> primenumbers(int n)

{

    vector<ll> primes;

    vector<bool> isPrime;

    isPrime = vector<bool>(n + 1, true);

    isPrime[0] = isPrime[1] = false;

    for (ll i = 2; i * i < n + 1; i++)

    {

        if (isPrime[i])

        {

            for (size_t j = i * i; j < isPrime.size(); j += i)

            {

                isPrime[j] = false;

            }

        }

    }

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

    {

        if (isPrime[i])

            primes.push_back(i);

    }

    return primes;

}



struct custom_hash

{

    static uint64_t splitmix64(uint64_t x)

    {

        x += 0x9e3779b97f4a7c15;

        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;

        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;

        return x ^ (x >> 31);

    }



    size_t operator()(uint64_t x) const

    {

        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

        return splitmix64(x + FIXED_RANDOM);

    }

};

template <typename T1, typename T2>



using safe_map = unordered_map<T1, T2, custom_hash>;



ll moduloMultiplication(ll x, ll y)

{

    ll res = 1;

    x = x % mod;



    while (y > 0)

    {

        if (y & 1)

        {

            res = (res * x) % mod;

        }



        y = y >> 1;

        x = (x * x) % mod;

    }

    return res;

}



ll modInverse(ll n)

{

    return moduloMultiplication(n, mod - 2);

}



ll nCr(ll n, ll r)

{

    if (n < r)

    {

        return 0;

    }

    if (r == 0)

    {

        return 1;

    }



    ll fac[n + 1];

    fac[0] = 1;

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

    {

        fac[i] = (fac[i - 1] * i) % mod;

    }



    return (fac[n] * modInverse(fac[r]) % mod * modInverse(fac[n - r]) % mod) % mod;

}



void longPrint(vii v)

{

    for (auto i : v)

    {

        cout << i << " ";

    }

    cout << endl;

}



void boolPrint(vii vis)

{

    for (auto i : vis)

    {

        cout << i << " ";

    }

    cout << endl;

}



template <typename T>

void inV(vector<T> &a)

{

    for (auto &i : a)

    {

        cin >> i;

    }

}



class SGT

{

public:

    vii seg;

    long long mini = 1e10;

    ll k;

    // vii lmax;

    // vii rmax;

    // vii fmax;

    SGT(ll n, ll k)

    {

        this->k = k;

        // fmax.resize(4 * n + 1, 0);

        // lmax.resize(4 * n + 1, 0);

        // rmax.resize(4 * n + 1, 0);

        seg.resize(4 * n + 1, 0);

    }



    void merge(ll idx, ll a, ll b)

    {

        seg[idx] = seg[a] & seg[b];

        mini = min(mini, abs(k - seg[idx]));

        // ll ok = rmax[a] + lmax[b];

        // fmax[idx] = max({fmax[a], fmax[b], ok});

        // lmax[idx] = max(lmax[a], seg[a] + lmax[b]);

        // rmax[idx] = max(rmax[b], rmax[a] + seg[b]);

    }



    void propagate(ll idx, ll lo, ll hi)

    {

    }



    void build(ll idx, ll lo, ll hi, vii &v)

    {

        if (lo == hi)

        {

            seg[idx] = v[lo];



            mini = min(mini, abs(k - seg[idx]));

            // fmax[idx] = max(0LL, v[lo]);

            // rmax[idx] = max(0LL, v[lo]);

            // lmax[idx] = max(0LL, v[lo]);

            return;

        }



        ll mid = (lo + hi) >> 1;

        build(2 * idx + 1, lo, mid, v);

        build(2 * idx + 2, mid + 1, hi, v);

        merge(idx, 2 * idx + 1, 2 * idx + 2);

    }



    void point_update(ll idx, ll lo, ll hi, ll i, ll val)

    {

        if (lo == hi)

        {

            seg[idx] = val;

            // fmax[idx] = max(0LL, val);

            // rmax[idx] = max(0LL, val);

            // lmax[idx] = max(0LL, val);

            return;

        }



        ll mid = (lo + hi) >> 1;

        if (i <= mid)

        {

            point_update(2 * idx + 1, lo, mid, i, val);

        }

        else

        {

            point_update(2 * idx + 2, mid + 1, hi, i, val);

        }



        merge(idx, 2 * idx + 1, 2 * idx + 2);

    }



    void range_update(ll idx, ll lo, ll hi, ll l, ll r, ll a, ll d)

    {

        // propagate(idx, lo, hi);



        // if (r < lo || hi < l || lo > hi)

        // {

        //     return;

        // }



        // if (lo >= l && hi <= r)

        // {

        //     lazy[idx] = (lo- l+1);

        //     lazy2[idx] = d;

        //     propagate(idx,lo,hi);

        //     return;

        // }



        // ll mid = (lo + hi) / 2;

        // range_update(2 * idx + 1, lo, mid, l, r, a,d);

        // range_update(2 * idx + 2, mid + 1, hi, l, r, a,d);

        // seg[idx] = merge(2*idx+1,2*idx+2);

    }



    ll query(ll idx, ll l, ll r, ll lo, ll hi)

    {

        // propagate(idx, lo, hi);



        if (r < lo || hi < l || lo > hi)

        {

            return 0;

        }



        if (lo >= l && hi <= r)

        {

            return seg[idx];

        }



        ll mid = (lo + hi) >> 1;

        ll left = query(2 * idx + 1, l, r, lo, mid);

        ll right = query(2 * idx + 2, l, r, mid + 1, hi);



        return max(left, right);

    }

};



ll modinv(ll p, ll q)

{

    ll exp = mod - 2;

    while (exp > 0)

    {

        if (exp & 1)

        {

            p = (p * q) % mod;

        }



        q = (q * q) % mod;

        exp >>= 1;

    }

    return p;

}



vii factors(ll x)

{

    vii ans;

    int i = 1;

    while (i * i <= x)

    {

        if (x % i == 0)

        {

            ans.pb(i);

            if (x / i != i)

            {

                ans.pb(x / i);

            }

        }

        i++;

    }



    return ans;

}



ll accumulate(vii &arr, ll n)

{

    ll sum = 0;

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

    {

        sum += arr[i];

    }

    return sum;

}



class DSU

{

public:

    vii par;

    vii size;

    ll maxi = 1;

    DSU(ll n)

    {

        par.resize(n + 1);

        size.resize(n + 1);

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

        {

            par[i] = i;

            size[i] = 1;

        }

    }

    ll getSize(ll a)

    {

        return size[find(a)];

    }



    ll find(ll x)

    {

        if (par[x] != x)

        {

            par[x] = find(par[x]);

        }

        return par[x];

    }



    bool merge(int u, int v)

    {

        int ulp_u = find(u);

        int ulp_v = find(v);

        if (ulp_u == ulp_v)

            return false;

        if (size[ulp_u] < size[ulp_v])

        {

            par[ulp_u] = ulp_v;

            size[ulp_v] += size[ulp_u];

            maxi = max(maxi, size[ulp_v]);

        }

        else

        {

            par[ulp_v] = ulp_u;

            size[ulp_u] += size[ulp_v];

            maxi = max(maxi, size[ulp_u]);

        }

        return true;

    }

};



ll binpow(ll base, ll exp)

{

    base %= mod;

    ll res = 1;

    while (exp > 0)

    {

        if (exp & 1)

        {

            res = res * base % mod;

        }

        base = base * base % mod;

        exp >>= 1;

    }

    return res;

}



bool comp(const vector<ll> &a, const vector<ll> &b)

{

    return a[2] < b[2];

}



static const ll inf = 1e18;

static const ll ins = -1e18;

static const ll maxM = 1e5 + 0;

static const ll maxN = 1e6 + 1;

vector<ll> computePrefixXOR(const vector<ll>& arr) {

    int n = arr.size();

    vector<ll> prefixXOR(n);

    prefixXOR[0] = arr[0];

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

        prefixXOR[i] = prefixXOR[i - 1] ^ arr[i];

    }

    return prefixXOR;

}



vector<ll> computeSuffixXOR(const vector<ll>& arr) {

    int n = arr.size();

    vector<ll> suffixXOR(n);

    suffixXOR[n - 1] = arr[n - 1];

    for (int i = n - 2; i >= 0; --i) {

        suffixXOR[i] = suffixXOR[i + 1] ^ arr[i];

    }

    return suffixXOR;

}

vector<ll> computePrefixAnd(const vector<ll>& arr) {

    int n = arr.size();

    vector<ll> prefixXOR(n);

    prefixXOR[0] = arr[0];

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

        prefixXOR[i] = prefixXOR[i - 1] & arr[i];

    }

    return prefixXOR;

}



vector<ll> computeSuffixAnd(const vector<ll>& arr) {

    int n = arr.size();

    vector<ll> suffixXOR(n);

    suffixXOR[n - 1] = arr[n - 1];

    for (int i = n - 2; i >= 0; --i) {

        suffixXOR[i] = suffixXOR[i + 1] & arr[i];

    }

    return suffixXOR;

}

void solution(){

    ll n,l,r;

    cin>>n>>l>>r;

    vii v(n);

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

        cin>>v[i];

    }

    vii aa,bb;

    for(ll i=0;i<r;i++) { aa.pb(v[i]);}

    for(ll i=l-1;i<n;i++) {bb.pb(v[i]);}

    

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

    

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

   ll sum1 = 0, sum2 = 0;

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

       sum1 += 1LL*aa[i];

       sum2 += 1LL*bb[i];

   }

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

}



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    ll tt = 1;

    cin >> tt;

    ll t = 1;

    while (t <= tt)

    {

        // cout << "Case #" << t << ": ";

        solution();

        t++;

    }

    return 0;

}