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

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

using namespace std;

int main(){

    int k;

    cin >> k;

    while(k--){

    int n,l,r;

    cin >> n >> l >> r;

    vector<long long int>arr1(n,0);

    for(int i=0;i<n;i++)cin >> arr1[i];

    priority_queue<long long int,vector<long long int>,greater<long long int>>q;

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

        q.push(arr1[i]);

    }

    long long int sum = 0;

    long long int sum1 = 0;

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

        sum+=q.top();

        q.pop(); 

    }

    while(!q.empty())q.pop();

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

        q.push(arr1[i]);

    }

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

        sum1+=q.top();

        q.pop(); 

    }

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

    }

}

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

#include <utility>  

// WA

// 1. overflow

// 2. re-initialize global variables for every test case.

// 3. edge cases like n=1

// 4. pass by value and pass by refrence for vectors , etc

// 5. Clear global arrays and vectors between test cases*/

 

// Run time error

// 1. division by zero.

// 2. array bounds.

 

// TLE

// 1. uncomment that #define endl '\n' line

// 2. try precomputating arr of sum,xor,freq,fst,lst,or any associative prop

// 3. avoid using memset in case of multiple test cases...

 

using namespace std;



#define beloo() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define fr(i, a, b) for (ll i = (a), _b = (b); i < _b; i++)

#define frr(i, a, b) for (ll i = (a), _b = (b); i > _b; i--)

#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)

#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)

#define FOR(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)

#define FORD(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)

#define REP(i, n) for (ll i = 0, _n = (n); i <= _n; i++)

#define REPD(i, n) for (ll i = (n) = ; i >= 0; i--)

#define foreach(it, ar) for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++)

#define fill(ar, val) memset(ar, val, sizeof(ar))

 

#define uint64 unsigned long long

#define int64 long long

#define Yes cout<<"YES"<<endl

#define No cout<<"NO"<<endl

#define el endl

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

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

#define pb push_back

#define mp make_pair

#define ff first

#define ss second

#define no ~

#define print(x) cout<<x<<"\n";

#define jay_mata_di() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)

#define display(a) for(auto i:a)cout<<i<<" ";cout nl;

#define unq(v)  v.resize(distance(v.begin(), unique(v.begin(), v.end())));

// make sure to sort before applying unique // else only consecutive duplicates would be removed 

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))

#define  to_low(s)         transform(s.begin(), s.end(), s.begin(), ::tolower);//convert string to lowercase

#define  to_up(s)          transform(s.begin(), s.end(), s.begin(), ::toupper);//convert string to uppercase









//lower bound of p mtlb p se just badda ya uske equal agr lower bound ke it ko -- kra to just chota milega agr ye it s.end hai to mtlb vo element ya usse badda element nhi hai aur agr ye sbegin hai to uss element se chota element nhi hai

//upper bound of p mtlb p se just badda uske equal nhi agr ye s.end() hai to mtlb uss element se badda element nhi hai aur agr iske it ko it-- kre to uss p se just chota ya uske equal element milega but agr ye s.begin hai to usme koi bhi element p ya p se chota nhi hai

 

typedef long long ll;

typedef long double lld;

typedef map<ll, set<ll>> msi;

 //// max_heap..{top()---> max first }

typedef priority_queue <ll, vector<ll>, greater<ll>> minQ; //// min_heap..{top()---> min first }

typedef set<ll>::iterator sit;

typedef map<ll,ll>::iterator mit;

typedef vector<ll>::iterator vit;

typedef unordered_map<char,ll> uncl; 



#define PI 3.1415926535897932385

#define INF 1000111222

#define eps 1e-7

#define MAXN 200005

#define MOD 1000000007

#define MOD1 998244353

const ll N = 1e5 + 5;

const ll dice = 1e6 + 5;

const ll mod = 1000000007; //1000000007; //998244353;

template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {

    for (auto &x : v) in >> x;

    return in;

}

template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) { 

    for (const T &x : v) out << x << ' '; 

    return out;

}



typedef pair<ll,ll> pii;

typedef set<pair<int,int>> spii;

typedef queue<int> qi;

typedef queue<ll> ql;

typedef deque<ll> dql;

typedef deque<pair<ll,ll>> dqpll;

typedef priority_queue<ll> pqll;

typedef pair<ll, ll> ii;

typedef pair<ll, ii> iii;

typedef vector<ii> vii;

typedef vector<ll> vi;

typedef vector<string> vs;

typedef vector<vector<ll>> vvi;

typedef vector<pair<int, int>> vpii;

typedef vector<pair<ll, ll>> vpll;

typedef map<ll, ll> mii;

typedef map<ll, ll> mll;

typedef map<ll, vi> mvl;

typedef unordered_map<ll , vi>unmpv;

typedef unordered_map<ll,ll> unmp; 

typedef set<ll> si;

typedef unordered_set<ll>ust;

typedef stack<ll> stk;







// sparcetable 

class sparcetable

{

    vector<vector<ll>>sptable;

    public:

        sparcetable(ll n,vector<ll>&nums){

                int k = log2(n);

                sptable.resize(k + 1,vector<ll>(n,0));

                sptable[0] = nums;

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

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

                    sptable[i][j] = min(sptable[i - 1][j],sptable[i - 1][j + (1 << (i - 1))]); 

                    // if we find sum or max in given range so replce min by given requiresment

                }

                }

        }

        ll query(ll l , ll r){

            ll count = r - l + 1;

            int k = log2(count);

            return min(sptable[k][l],sptable[k][r - (1 << k) + 1]);

        }





};

class MinSegmentTree {

public:

    vector<long long> tree;

    int n;



    void build(int v, int tl, int tr, const vector<long long>& a) {

        if (tl == tr) {

            tree[v] = a[tl];

        } else {

            int tm = (tl + tr) >>1;

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

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

            tree[v] = tree[2 * v + 1]+ tree[2 * v + 2]; // Min operation

        }

    }



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

        if (l > r) return 0; // Change identity to LLONG_MAX for minimum

        if (tl == l && tr == r) {

            return tree[v];

        }

        int tm = (tl + tr) >>1;

        ll left = query(2 * v + 1, tl, tm, l, min(r, tm));

        ll right = query(2 * v + 2, tm + 1, tr, max(l, tm + 1), r);

        return left+right; // Min operation

    }



    void update(int v, int tl, int tr, int pos, long long new_val) {

        if (tl == tr) {

            tree[v] = new_val;

        } else {

            int tm = (tl + tr) / 2;

            if (pos <= tm) {

                update(2 * v + 1, tl, tm, pos, new_val);

            } else {

                update(2 * v + 2, tm + 1, tr, pos, new_val);

            }

            tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]); // Min operation

        }

    }



public:

    MinSegmentTree(const vector<long long>& a) {

        n = a.size();

        tree.resize(4 * n);

        build(0, 0, n - 1, a);

    }



    long long query(int l, int r) {

        return query(0, 0, n - 1, l, r);

    }



    void update(int pos, long long new_val) {

        update(0, 0, n - 1, pos, new_val);

    }

};



bool isleap(int year){

   if(year % 400 == 0)return 1;

   else if(year % 100  == 0)return 0;

   else if(year % 4 == 0)return 1;

   else return 0;

}

int cylce[2000001] = {0};

int par[2000001] = {-1};



vi vis;

bool iscycle;

void dfs(int u , mvl& adj){

    if(adj[u].size() != 2){

        iscycle = 0;

    }

    vis[u] = 1;

    for(auto it: adj[u]){

        if(!vis[it]){

            dfs(it,adj);

        }

    }

     

}

bool isprime(ll n){

    if(n == 1)return 0;

    FOR(i , 2 , sqrt(n)){

        if(n % i == 0)return 0;

    }

    return 1;

}

int smalldivisor(ll n){

    if(!(n & 1))return 2;

    for(int i = 3; i*i <= n; i++){

        if(n % i == 0)return i;

    }

    return n;

}





#define BIT(n) (1 << (n))

#define AND(a, b) ((a) & (b))

#define OR(a, b) ((a) | (b))

#define XOR(a, b) ((a) ^ (b))

#define sqr(x) ((x) * (x))

#define popCnt(x) (__builtin_popcountll(x))

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

#define min4(a, b, c, d) min(d, min(c, min(a, b)))

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

#define max4(a, b, c, d) max(d, max(c, max(a, b)))

#define uprbnd(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin()) //returns indx of lower bound (>x)

#define lwrbnd(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin()) //returns indx of lower bound (>=x)

#define precisely(val,x) cout << setprecision(x) << fixed << val << endl

#define get_sum(a) accumulate(a.begin(), a.end(), 0LL)

#define chill(a,b) a=min(a,b) 

#define savdhan(a,b) a=max(a,b) 





//  smallest prime factor of number;

ll spf[dice] = {0};

void createSieve(){

    FOR(i , 0, dice){

        spf[i] = i;

    }

    FOR(i , 2 , sqrt(dice)){

        if(spf[i] == i){

            for(ll j = i * i; j <= dice; j += i){

                if(spf[j] == j){

                    spf[j] = i;

                }

            }

        }

    }

}

void findfactor(ll n,vi& factor){

    FOR(i , 1 , sqrt(n)){

        if(n % i == 0){

            if(n/i == i){

                factor.pb(i);

            }else{

                factor.pb(i);

                factor.pb(n/i);

            }

        }



    }

}

bool valid(ll workingday , ll p , ll l , ll t,ll n){

        ll unblock = ceil(n/7.00);

        ll ans = (workingday * l) + (min(workingday * 2 , unblock) * t);

        return ans >= p;

      

}

int dx[] = {-1,0,1,0};

int dy[] = {0,1,0,-1};

ll p = 0;

void dfs(int i , int j ,int n , int m ,vvi & mat,vector<vector<bool>>&vis){

   if(i < 0 || j < 0 || i >=n || j >= m || mat[i][j] == 0 || vis[i][j]){

    return;

   }

   vis[i][j] = 1;

   p += mat[i][j];

   rep(k , 4){

     int new_i = i + dx[k];

     int new_j = j + dy[k];

     dfs(new_i,new_j,n,m,mat,vis);

   }

}





bool cmp(pair<int,int> p1,pair<int,int>p2){

    if(p1.ff == p2.ff){

       return p1.ss < p2.ss;

    }

    return p1.ff > p2.ff;

}



void solve(){

   ll t;

   cin >> t;

   while(t--){

      ll n,l , r;

      cin >> n >> l >> r;

      l--;

      r--;

      vi a(n);

      cin >> a;

      vi left,right;

      rep(i , n){

        if(i <= r)right.pb(a[i]);

        if(i >= l)left.pb(a[i]);

      }

     sort(all(right));

     sort(all(left));

     ll ansl = 0 , ansr = 0;

     ll sz = r - l + 1;

     rep(i , sz){

        ansl += left[i];

        ansr += right[i];

     }

     print(min(ansl,ansr));

    

   }

 

}



int main()

{

    solve();

   

	return 0;

}