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

Solution 1 (runtime: 187 ms):
// #include <bits/stdc++.h>
// #define vi vector<int>
// #define ll long long int
// #define lb long double
// #define vii vector<long long int>
// #define vs vector<string>
// #define f(i, vec) for (auto i : vec)
// #define fr(i, n) for (int i = 0; i < n; i++)
// #define frs(i,j,n) for(int i =j;i<n;i++)
// #define srt(arr) sort(arr.begin(),arr.end())
// #define rev(arr) reverse(arr.begin(),arr.end())
// #define minn(arr) *min_element(arr.begin(),arr.end())
// using namespace std;

// int mod(int a){
//    if(a<0) return -1*a;
//    return a;
// }

// bool cmp(pair<int,int> x,pair<int,int> y){
//     if(x.first<y.first) return true;
//     else if(x.first>y.first) return false;
//     else{
//        if(x.second<=y.second) return true;
//        else return false;
//     }
// }

// void solve()
// {  
  
// }
// int main()
// {

//    int t;
//    cin >> t;
//    while (t--)
//    {
//       solve();
//    }
// //    solve();
// }



// /*
//     int n;
//     cin>>n;
//     vi arr(n,0);
//     fr(i,n) cin>>arr[i];
//     srt(arr);

//     ll count = 0;
//     int diff = 0;
//     int temp = n;

//     while (temp-diff>0)
//     {
//         count+=temp-diff;
//         diff+=2;
//     }
//         cout<<count<<"\n";

//     fr(i,n-1){
//        if(arr[i]==arr[i+1]){
//           count += min(i,n-i-2)+1;
//        }
//     }
//     cout<<count<<"\n";
//     *//
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long int
#define lb long double
#define vii vector<long long int>
#define vs vector<string>
#define f(i, vec) for (auto i : vec)
#define fr(i, n) for (int i = 0; i < n; i++)
#define frs(i,j,n) for(int i =j;i<n;i++)
#define srt(arr) sort(arr.begin(),arr.end())
using namespace std;
 
 
void solve()
{ 
   ll n,l,r;
   cin>>n>>l>>r;
   ll ans1 = 0,ans2=0;
   vii arr(n,0);

   fr(i,n){
      
      cin>>arr[i];

      if(i>=l-1&&i<r) {
         ans1 += arr[i];
         ans2 += arr[i];
      }
   }

   sort(arr.begin(),arr.begin()+l-1);
   sort(arr.begin()+l-1,arr.begin()+r);
   sort(arr.begin()+r,arr.end());

   int i = 0,j=r-1;
   while (i<l-1&&j>=l-1&&arr[i]<arr[j])
   {
       ans1+=arr[i]-arr[j];
       i++;
       j--;
   }
   i = r ,j = r-1;
   while (i<n && j>=l-1 && arr[i] < arr[j])
   {
       ans2+=arr[i]-arr[j];
       i++;
       j--;
   }

   cout<<min(ans1,ans2)<<"\n";
}
int main()
{
 
   int t;
   cin >> t;
   while (t--)
   {
      solve();
   }
// solve();
}

Solution 2 (runtime: 218 ms):
/*Darshan Bhimani - Svnit*/



#include <bits/stdc++.h>

#include <iostream>

#include <string.h>

#include <math.h>

#include <bitset>

#include <vector>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

using namespace std;

#define ull unsigned long long int

#define uld unsigned long double

#define pi 3.14159265359

#define pb push_back

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

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

#define cn cout << "NO" << endl;

#define cy cout << "YES" << endl;

#define ss second

#define ll long long

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

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

template<class T> using oset = tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;



int main()

{

    int t; cin>>t;

    while(t--)

    {

        ll n, l, r;

        cin>>n>>l>>r;



        ll a[n];



        FOR(i,0,n){

            cin>>a[i];

        }



        vector<ll> lv, mv, rv;



        mv.push_back(0);

        lv.push_back(0);

        rv.push_back(0);



        FOR(i,0,l-1){

            lv.push_back(a[i]);

        }

        FOR(i,l-1,r){

            mv.push_back(a[i]);

        }

        FOR(i,r,n){

            rv.push_back(a[i]);

        }



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

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

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



        FOR(i,1,lv.size()){

            lv[i]=lv[i-1]+lv[i];

            // cout<<lv[i]<<" ";

        }

        // cout<<endl;



        FOR(i,1,mv.size()){

            mv[i]=mv[i-1]+mv[i];

            // cout<<mv[i]<<" ";

        }

        // cout<<endl;



        FOR(i,1,rv.size()){

            rv[i]=rv[i-1]+rv[i];

            // cout<<rv[i]<<" ";

        }

        // cout<<endl<<endl;



        ll ans= mv[mv.size()-1];



        FOR(i,0,min(mv.size(), lv.size())){

            ans=min(ans, lv[i]+mv[mv.size()-1-i]);

        }

        FOR(i,0,min(rv.size(), mv.size())){

            ans=min(ans, rv[i]+mv[mv.size()-1-i]);

        }



        cout<<ans<<endl;

    }

}