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

Solution 1 (runtime: 93 ms):
// Problem: B. Subsequence Update

// Contest: Codeforces - Codeforces Round 1000 (Div. 2)

// URL: https://codeforces.com/contest/2063/problem/B

// Memory Limit: 256 MB

// Time Limit: 1500 ms

// by znzryb

//

// Powered by CP Editor (https://cpeditor.org)



#include <bits/stdc++.h>

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

#define ROF(i, a, b) for (int i = (a); i >= (b); --i)

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

#define CLR(i, a) memset(i, a, sizeof(i))

#define fi first

#define se second

#define pb push_back

#define SZ(a) ((int)a.size())



using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<ll, ll> pll;

typedef array<ll, 3> arr;

typedef double DB;

typedef pair<DB, DB> pdd;

constexpr ll MAXN = static_cast<ll>(1e6) + 10, INF = static_cast<ll>(5e18) + 3;



ll N, L, R, T, A[MAXN];



inline void solve() {

  cin >> N >> L >> R;

  ll sum = 0;

  FOR(i, 1, N) {

    cin >> A[i];

    if (i >= L && i <= R) {

      sum += A[i];

    }

  }

  sort(A + 1, A + L);

  sort(A + L, A + R + 1);

  sort(A + R + 1, A + N + 1);

  ll ldec = 0, rdec = 0;  // 左右可减少值

  for (int i = 1, j = R; i <= L - 1 && j >= L; ++i, --j) {

    if (A[i] >= A[j]) {

      break;

    }

    ldec += A[j] - A[i];

  }

  for (int i = R+1, j = R; i <= N && j >= L; ++i, --j) {

    if (A[i] >= A[j]) {

      break;

    }

    rdec += A[j] - A[i];

  }

  cout << sum - max(rdec, ldec) << '\n';



  // cerr << sum << ' ' << ldec << ' ' << rdec << '\n';

}



int main() {

  ios::sync_with_stdio(false);

  cin.tie(0);

  cout.tie(0);

  cin >> T;

  while (T--) {

    solve();

  }

  return 0;

}

/*



*/

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lc(t) ll t; cin >> t;
#define f(i,a,n) for (ll i=a; i<n; i++)
#define sp cout << " ";
#define nl cout << "\n";
#define fmc(i,n,a) ll a[n]; for (ll i=0; i<n; i++) cin >> a[i]
#define fout(i,n,a) for (ll i=0; i<n; i++) cout << a[i] << " "
#define pb push_back
#define all(x) x.begin(), x.end()
#define all(x,a) x, x+a
#define sz(x) (ll)x.size()
#define vi vector<int>
#define vll vector<ll>
#define F first
#define S second
#define endl "\n"
#define mod 1000000007
#define inf 1000000000000000000
#define pi 3.141592653589793238462643383279502884197169399
#define krish ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ld long double
 
bool isprime (ll n)
{
    if (n<=1) return false;
    if(n==2 || n==3) return true;
    if(n%2==0 || n%3==0) return false;
    for (ll i=5; i<=sqrt(n); i+=6)  if (n%i==0 || n%(i+2)==0) return false;
    return true;
}

bool s(ll a, ll b)
{
    return a>b;
}
 
void fun()
{
    lc(n);
    lc(l);
    lc(r);
    ll sum = 0, sum1 = 0, min;
    vll a, b, c;
    f(i,0,n)
    {
        lc(t);
        if ( i<l-1 ) a.pb(t);
        else if ( i>=l-1 && i<r ) b.pb(t), sum += t;
        else c.pb(t);
    }
    sort (a.begin(), a.end());
    sort (b.begin(), b.end());
    sort (c.begin(), c.end());
    sum1 = sum, min = sum;
    ll i=0;
    // cout << sz(a) << ' ' << sz(b) << ' ' << sz(c) << endl;
    if ( sz(a)>0 )
    {
        // cout << " hello ";
        while ( i<sz(a) && i<sz(b) && a[i]<b[r-l-i] )
        {
            sum1 += (a[i]-b[r-l-i]);
            i++;
            // cout << " a[i] ";
        }
    }
    min = sum1<min ? sum1 : min;
    i = 0, sum1 = sum;
    if ( sz(c)>0 )
    {
        while ( i<sz(c) && i<sz(b) && c[i]<b[r-l-i] )
        {
            sum1 += (c[i]-b[r-l-i]);
            i++;
        }
    }
    min = sum1<min ? sum1 : min;
    cout << min << endl;
    return;
}
 
int main()
{
    krish;
    lc(t);
    // ll t = 1;
    while (t--) fun();
    return 0;
}