Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
// ---------------------------------

// READ { WHOLE } QUESTION PROPERLY. |

// ---------------------------------

// --------------------------------------------

// READ QUESTION CAREFULLY IN EDUCATIONAL ROUND

// --------------------------------------------

// understand question properly and have patience if not able to understand question in first time.

// -----------------------------------------------

// | VERY IMPORTANT : OBSERVE TESTCASES PROPERLY. |

// -----------------------------------------------

// understand question properly and fast.

// don't do faasam faas if you know its easy question or you have to face a lot of repurcussion.

// don't do stupidness in div 4 be calm and do it.

// if not able to do find out solution of any question jump to another question.

// Keep Precomputation in mind if it can be used.

// If questions are done early don't be happy try next question very seriously



#include <bits/stdc++.h>



using namespace std;



typedef long long ll;

typedef long double ld;

typedef double dd;

typedef float fl;



const ll N = 1e6+7;



vector<ll> binary(ll n){

    vector<ll> v;

    while(n!=0){

        v.push_back(n%2);

        n=n/2;

    }

       // reverse(v.begin(),v.end());

    return v;

}

const int MOD = 1e9 + 7;

const int MAX_N = 2.1e5 + 1;

vector<long long> fact(MAX_N);

vector<long long> invFact(MAX_N);

void precomputeFactorials() {

    fact[0] = 1;

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

        fact[i] = (fact[i - 1] * i) % MOD;

    }

}

long long modInverse(long long x, long long mod) {

    long long result = 1, power = mod - 2;

    while (power) {

        if (power & 1) result = (result * x) % mod;

        x = (x * x) % mod;

        power >>= 1;

    }

    return result;

}

void precomputeInvFactorials() {

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

        invFact[i] = modInverse(fact[i], MOD);

    }

}

long long comb(int n, int k) {

    if (k > n || k < 0) return 0;

    return fact[n] * invFact[k] % MOD * invFact[n - k] % MOD;

}

ll power(ll a,ll b){

    ll ans=1;

    while(b){

        if(b&1) ans=ans*a;

        a=a*a;

        b>>=1;

    }

    return ans;

}



vector<bool> isPrime(N,1);



bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){

        return a.second<b.second;

}



int main(){

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

//   for(int i=2;i*i < N;i++){

//       if(isPrime[i]==true){

//           for(int j=2*i;j<N;j+=i){

//               isPrime[j]=false;

//           }

//       }

//   }



    ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);



    int t=1;

    cin >> t;

    while(t--){

        ll n,l,r;

        cin>>n>>l>>r;

        vector<ll> v(n);

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

            cin>>v[i];

        }

        vector<ll> w,x;

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

            w.push_back(v[i]);

        }

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

            x.push_back(v[i]);

        }

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

            x.push_back(v[i]);

        }

        // cout<<w.size()<<x.size()<<"\n";

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

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

        ll left=0,right=w.size()-1;

        while(right>=0 && left<x.size()){

           if(w[right]>=x[left]) swap(x[left],w[right]);

           else break;

           left++;

           right--;

        }

        ll sum=0;

        for(int i=0;i<w.size();i++){

            sum+=w[i];

        }

        cout<<sum<<"\n";

    }

    return 0;

}