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

Solution 1 (runtime: 187 ms):
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
#define  vec vector<long long>
int main()
{
ll t;
cin>>t;
while(t--)
{
    ll n,l,r;
    cin>>n>>l>>r;
    vec a(n);
    for(auto &i:a)cin>>i;
    l--;r--;
    ll suml=0,sumr=0;
    priority_queue<ll,vector<ll>,greater<ll>>st1,st2;
    for(ll i=l;i<=r;i++){st1.push(a[i]);st2.push(a[i]);}
    for(ll i=0;i<l;i++)st1.push(a[i]);
    for(ll i=r+1;i<n;i++)st2.push(a[i]);
    for(ll i=l;i<=r;i++){
        suml += st1.top();
        st1.pop();
    }
    for(int i=l;i<=r;i++){
        sumr += st2.top();
        st2.pop();
    }
    cout<<min(suml,sumr)<<endl;
}
return 0;
}

Solution 2 (runtime: 108 ms):
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define int long long
#define ll long long
#define ld long double
#define enter cout << endl;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key

// Custom comparator for pairs

bool comp(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first != b.first)
    {
        return a.first < b.first;
    }
    else
    {
        return abs(a.first - a.second) > abs(b.first - b.second);
    }
}

// Define the ordered set of pairs
struct pair_compare
{
    bool operator()(const pair<int, int> &a, const pair<int, int> &b) const
    {
        // Compare first by the first element of the pair
        if (a.first != b.first)
            return a.first < b.first;
        // If the first elements are the same, compare by the second element
        return a.second < b.second;
    }
};
typedef tree<pair<int, int>, null_type, pair_compare, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

/* Disjoint Set*/
class DisjointSet
{

public:
    vector<int> rank, parent, size;
    DisjointSet(int n)
    {
        rank.resize(n + 1, 0);
        parent.resize(n + 1);
        size.resize(n + 1);
        for (int i = 0; i <= n; i++)
        {
            parent[i] = i;
            size[i] = 1;
        }
    }

    int findUPar(int node)
    {
        if (node == parent[node])
            return node;
        return parent[node] = findUPar(parent[node]);
    }

    void unionBySize(int u, int v)
    {
        int ulp_u = findUPar(u);
        int ulp_v = findUPar(v);
        if (ulp_u == ulp_v)
            return;
        if (size[ulp_u] < size[ulp_v])
        {
            parent[ulp_u] = ulp_v;
            size[ulp_v] += size[ulp_u];
        }
        else
        {
            parent[ulp_v] = ulp_u;
            size[ulp_u] += size[ulp_v];
        }
    }
};

/* Power function with Modulo */
int po(int x, int n, int m)
{
    if (x == 0)
        return 0;
    if (n == 0)
        return 1;

    int r = po(x, n / 2, m);
    r = (r * r) % m;

    if (n % 2 == 0)
        return r;
    else
        return (r * x) % m;
};

// int MOD = 1e9 + 7;

int mod = 1e9 + 7;

void _2pointer_method()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    map<int, int> mp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];

        mp[a[i]]++;
    }

    int len = mp.size();
    vector<int> res(len);
    vector<int> freq(len);

    int i = 0;

    for (auto val : mp)
    {
        res[i] = val.first;
        freq[i] = val.second;
        i++;
    }

    int ma = 0;
    int cnt = 0;

    int left = 0;
    int right = 0;

    while (right < len)
    {
        if (right == left || res[right] == res[right - 1] + 1)
        {
            cnt += freq[right];

            if (right - left + 1 > k)
            {
                cnt -= freq[left];
                left++;
            }

            ma = max(ma, cnt);
            right++;
        }
        else
        {
            left = right;
            cnt = 0;
        }
    }

    cout << ma << endl;
}

int power(int n, int m, int mod)
{
    if (m == 0)
        return 1;
    if (n == 0)
        return 0;

    int curr = power(n, m / 2, mod);
    curr = (curr * curr) % mod;

    if (m % 2 == 0)
        return curr;
    else
        return (curr * n) % mod;
}

int mod_inverse(int n, int mod)
{
    if (n == 0)
        return 0;
    return power(n, mod - 2, mod);
}

class segT
{
public:
    int len;
    vector<int> t;
    vector<int> lazy;
    vector<int> chk;

    segT(int n)
    {
        len = n;
        t.resize(4 * n + 1, 0);
        lazy.resize(4 * n + 1, 0);
        chk.resize(4 * n + 1, 0);
    }

    void build(int v, int tl, int tr, vector<int> &a)
    {
        if (tl == tr)
        {
            t[v] = a[tl];
            return;
        }

        int tm = (tl + tr) / 2;

        build(2 * v + 1, tl, tm, a);
        build(2 * v + 2, tm + 1, tr, a);

        t[v] = t[2 * v + 1] + t[2 * v + 2];
        // t[v] = __gcd(t[2 * v + 1], t[2 * v + 2]);
        // t[v] = min(t[2 * v + 1], t[2 * v + 2]);
    }

    void update(int v, int tl, int tr, int l, int r, int val)
    {

        if (chk[v])
        {
            t[v] = (tr - tl + 1) * lazy[v];
            // t[v] += lazy[v];

            if (tl != tr)
            {
                // lazy[2 * v + 1] += lazy[v];
                lazy[2 * v + 1] = lazy[v];
                chk[2 * v + 1] = 1;

                // lazy[2 * v + 2] += lazy[v];
                lazy[2 * v + 2] = lazy[v];
                chk[2 * v + 2] = 1;
            }

            lazy[v] = 0;
            chk[v] = 0;
        }

        if (tr < l || tl > r)
            return;

        if (tl >= l && tr <= r)
        {
            t[v] = (tr - tl + 1) * val;
            // t[v] += val;
            if (tl != tr)
            {
                // lazy[2 * v + 1] += val;
                lazy[2 * v + 1] = val;
                chk[2 * v + 1] = 1;

                // lazy[2 * v + 2] += val;
                lazy[2 * v + 2] = val;
                chk[2 * v + 2] = 1;
            }
            return;
        }
        int tm = (tl + tr) / 2;
        update(2 * v + 1, tl, tm, l, r, val);
        update(2 * v + 2, tm + 1, tr, l, r, val);

        // t[v] = max(t[2 * v + 1], t[2 * v + 2]);
        t[v] = (t[2 * v + 1] + t[2 * v + 2]);
    }

    int query(int v, int tl, int tr, int l, int r)
    {

        if (chk[v])
        {
            t[v] = (tr - tl + 1) * lazy[v];
            // t[v] += lazy[v];

            if (tl != tr)
            {
                // lazy[2 * v + 1] += lazy[v];
                lazy[2 * v + 1] = lazy[v];
                chk[2 * v + 1] = 1;

                // lazy[2 * v + 2] += lazy[v];
                lazy[2 * v + 2] = lazy[v];
                chk[2 * v + 2] = 1;
            }

            chk[v] = 0;
            lazy[v] = 0;
        }

        if (tr < l || tl > r)
            return 0;
        // return LLONG_MAX;
        // return 1;

        if (tl >= l && tr <= r)
            return t[v];

        int tm = (tl + tr) / 2;
        int left = query(2 * v + 1, tl, tm, l, r);
        int right = query(2 * v + 2, tm + 1, tr, l, r);

        return left + right;
        // return min(left, right);
        // return __gcd(left, right);
    }

    void build(vector<int> &a)
    {
        build(0, 0, len - 1, a);
    }
    void update(int l, int r, int val)
    {
        update(0, 0, len - 1, l, r, val);
    }
    int query(int l, int r)
    {
        return query(0, 0, len - 1, l, r);
    }
};

int range(int l, int r)
{
    while (l < r)
    {
        r = (r & (r - 1));
    }
    return r;
}

long long binomial(int n, int k)
{
    if (k > n)
        return 0;
    long long res = 1;
    for (int i = 0; i < k; i++)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

pair<int, int> maxXORPairInRange(int L, int R)
{
    // Get XOR of limits
    int LXR = L ^ R;

    // Find the position of the most significant bit (MSB)
    int msbPos = 0;
    while (LXR)
    {
        msbPos++;
        LXR >>= 1;
    }

    // Maximum XOR value achievable
    int maxXOR = (1 << msbPos) - 1;

    // Build the two numbers using MSB
    int num1 = L | (maxXOR >> 1); // Largest number with flipped MSB bits
    int num2 = num1 ^ maxXOR;     // Pair to maximize XOR

    return {num1, num2};
}
int ct(int a, int b, int c)
{
    return (a ^ b) + (b ^ c) + (c ^ a);
}
vector<int> sieve;
int countlessthanx(pbds &s, int x)
{
    return s.order_of_key(x);
}
int elementAtIndexK(pbds &s, int k)
{
    // zero based index
    return *s.find_by_order(k);
}
void debugg(vector<int> &a)
{
    for (auto val : a)
    {
        cout << val << " ";
    }
    cout << endl;
}
typedef pair<int, int> pii;

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


    vector<int> c;
    for(int i = 0; i < n; i++){
        if(i < l-1){
            c.push_back(a[i]);
        }
    }
    vector<int> d;
    for(int i = r; i < n; i++){
        d.push_back(a[i]);
    }
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    sort(d.begin(), d.end());
    int sum = accumulate(b.begin(), b.end(), (int)0);

    int j = b.size()- 1;
    int ans = sum;
    int curr = 0;
    int curr2 = 0;
    for(int i = 0; i < c.size(); i++){
        if(j < 0) break;
        curr += b[j];
        curr2 += c[i];
        ans = min(ans, sum + curr2 - curr);
        j--;
    }
    j = b.size()- 1;
    curr = 0;
    curr2 = 0;
    for(int i = 0; i < d.size(); i++){
        if(j < 0) break;
        curr += b[j];
        curr2 += d[i];
        ans = min(ans, sum + curr2 - curr);
        j--;
    }
    cout << ans << endl;
}

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

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

    int q = 1;

    cin >> q;

    while (q--)
    {

        solve();
    }

    return 0;
}