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

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

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<bool> vb;

typedef vector<char> vc;

typedef vector<string> vs;

typedef vector<ll> vl;

typedef vector<vi> vvi;

typedef vector<vl> vvl;

typedef vector<vc> vvc;

typedef vector<vs> vvs;

typedef pair<ll, ll> pii;

typedef pair<ll, ll> pll;

typedef vector<pii> vii;

typedef vector<pll> vll;



#define mtc() ll t; cin>>t; while(t--) solve();



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

#define FORN(a, b, c) for (ll (a) = (b); (a) <= (c); ++(a))

#define REP(i, n) FOR(i, 0, n)

#define REPN(i, n) FORN(i, 1, n)

#define pb push_back

#define ppb pop_back

#define pf push_front

#define ppf pop_front

#define mp make_pair

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

#define allr(a) a.begin(), a.end(), greater<pair<ll,ll>>()

#define py cout << "YES\n";

#define pn cout << "NO\n";



// Operators overload

template <typename T> // cin >> vector<T>

istream &operator>>(istream &istream, vector<T> &v) {

  for (auto &it : v)

    cin >> it;

  return istream;

}

template <typename T> // cout << vector<T>

ostream &operator<<(ostream &ostream, const vector<T> &c) {

  for (auto &it : c)

    cout << it << " ";

  return ostream;

}



vb isprime(100001, true);



// Sieve of Eratosthenes to determine prime numbers up to 100,000

void sieve(ll n) {

    isprime[0] = false;

    isprime[1] = false;

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

        if (isprime[i] == true) {

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

                isprime[j] = false;

            }

        }

    }

}



static bool cmp(pair<char, ll> &a, pair<char, ll> &b) {

  return a.second < b.second;

}



bool is_sorted(vi a) {

  for (ll i = 0; i < a.size() - 1; ++i) {

    if (a[i] >= a[i + 1]) {

      return false;

    }

  }

  return true;

}



ll mod = 1000000007;

int gcd(int a, int b) {

  return b == 0 ? a : gcd(b, a % b);

}

int lcm(int a, int b) {

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

}



void solve(){

  ll n,l,m;

  cin>>n>>l>>m;

  l--,m--;

  vl a(n);

  cin>>a;



  vl left(a.begin(), a.begin()+m+1);

  

  

  vl right(a.begin()+l,a.end());

  

  sort(all(left));

  sort(all(right));



  // cout<<left<<"\n";

  // cout<<right<<"\n"; 

  ll le=accumulate(left.begin(),left.begin()+(m-l+1),0ll);

  // cout<<le<<"\n";

  ll r=accumulate(right.begin(),right.begin()+(m-l+1),0ll);

  // cout<<r<<"\n";

  cout<<min(le,r)<<"\n";

  



}



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  mtc();

  // solve();



  return 0;

}



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

using namespace std;



typedef long long ll;



void solve() {

    int n, l, r;

    cin >> n >> l >> r;

    --l, --r;

    vector<int> ls(l), sq(r-l+1), rs(n-r-1);

    ll sum = 0;

    for(int& x : ls) cin >> x;

    for(int& x : sq) { cin >> x; sum += x; }

    for(int& x : rs) cin >> x;

    sort(ls.begin(), ls.end()), sort(sq.begin(), sq.end(), greater<>()), sort(rs.begin(), rs.end());

    ll rsum = sum, lsum = sum;

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

        if(sq[i] < rs[i]) break;

        rsum -= sq[i] - rs[i];

    }

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

        if(sq[i] < ls[i]) break;

        lsum -= sq[i] - ls[i];

    }

    cout << min(lsum, min(rsum, sum)) << '\n';

}



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t;

    cin >> t;

    while(t--) solve();

    return 0;

}