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

Solution 1 (runtime: 187 ms):
#include<bits/stdc++.h>
using namespace std;
 
// ************// code snippet of ordered_set  //*********************************************
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<int>, __gnu_pbds::rb_tree_tag, 
// __gnu_pbds::tree_order_statistics_node_update> ordered_set;
 
// *******************************************************************************************
 
#define pii pair<int,int>
#define int long long int
#define pb push_back
#define eb emplace_back
#define db long double
#define f first 
#define s second
#define vi vector<int> 
#define vp vector<pii>
#define vc vector<char>
#define str string
#define vb vector<bool> 
#define vvi vector<vector<int>> 
#define vvs vector<vector<str>>
#define vvb vector<vector<bool>> 
#define vvp vector<vector<pii>>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vvvi vector<vector<vector<int>>>
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define frs(i,a,b,k) for(int i=a;i<=b;i+=k)
#define frrs(i,a,b,k) for(int i=a;i>=b;i-=k)
#define rs(a,b) resize(a,b)
#define b() begin()
#define e() end()
#define INF 1e18
const int mod=1e9+7;
const int N=10;
 
// vector<bool>primes(N,true);
// vector<int>prms(N,-1);
 
// auto max(auto a,auto b){if(a>b) return a;return b;}
// auto min(auto a,auto b){if(a<b) return a;return b;}
// tuple<int,int,int> eea(int a,int b){if(b==0) return {1,0,a};int z=a;auto t=eea(b,z%b);return {get<1>(t),get<0>(t)-(a/b)*get<1>(t),get<2>(t)};}
// int mul(int a,int b,int p){int val=0;while(b>0){if(b&1) val=(val+a)%p;a=(a+a)%p;b>>=1;}return val;}  
// int gcd(int a,int b){while(a>0 and b>0){if(a>b) a=a%b;else b=b%a;}return a==0?b:a;}
// void matrix_mul(vector<vector<int>>a,vector<vector<int>>&b,vector<vector<int>>&c){int r1=a.size(),c1=a[0].size();int r2=b.size(),c2=b[0].size();c.resize(r1,vector<int>(c2));for(int i=0;i<r1;i++){for(int j=0;j<c1;j++){for(int k=0;k<r2;k++){c[i][j]+=a[i][k]*b[k][j];}}}}
// void sieve(int n){primes[0]=primes[1]=false;for(int i=2;i*i<=n;i++){if(primes[i]){for(int j=i*i;j<=n;j+=i){primes[j]=false;}}}}
// int expo(int a,int b){int val=1;while(b>0){if(b&1) val=val*a;a=a*a;}return val;}
// void sieve(){for(int i=2;i<N;i++){prms[1]=1;if(prms[i]==-1){for(int j=i;j<N;j+=i){if(prms[j]==-1){prms[j]=i;}}}}}
 
   
// *************// Z-algorithm // ************************************************************
   /*
 
    vi Z(st.size());
    Z[0]=0; // actually Z[0] is undefined
 
    int l=0,r=0;
    for(int i=0;i<st.size();i++){
        if(i<=r){
            Z[i]=min(r-i+1,Z[i-l]);
        }
        while(i+Z[i]<st.size() and s[Z[i]]==s[i+Z[i]]) Z[i]++;
        if(i+Z[i]>r+1){
            r=i+Z[i]-1;
            l=i;
        }
    }
 
    */
// *******************************************************************************************
 
//***************// kmp algorithm //**********************************************************
    /*
    
    vi lsp(st.size());
    lsp[0]=0;
    int index=0;
    int i=1;
    while(i<st.size()){
        if(st[i]==st[index]) lsp[i++]=++index;
        else{
            if(index) index=lsp[index-1];
            else lsp[i++]=0;
        }
    }
    
    */
//*********************************************************************************************
 
int n,l,r;
vi arr;
vi a,b,c;

bool cmp(int a,int b){
    return a>b;
}

void main1(){
    // your code goes here 
    cin>>n>>l>>r;
    arr.rs(n+1,0);
    fr(i,1,n) cin>>arr[i];

    fr(i,1,l-1) a.pb(arr[i]); // l-1
    fr(i,l,r) b.pb(arr[i]); // r-l+1
    fr(i,r+1,n) c.pb(arr[i]); // n-r

    sort(a.b(),a.e()); 
    sort(b.b(),b.e(),cmp);
    sort(c.b(),c.e());

    int sum=0;
    fr(i,l,r) sum+=arr[i];

    if(l>1){
        int low=0,high=min(r-l,l-2);
        while(low<=high){
            int mid=low+(high-low)/2;
            if(a[mid]<b[mid]){
                low=mid+1;
            }else high=mid-1;
        }

        int sum1=0;
        fr(i,0,r-l){
            if(i<=high) sum1+=a[i];
            else sum1+=b[i];
        }
        sum=min(sum,sum1);
    }

    if(r<n){
        int low=0,high=min(r-l,n-r-1);
        while(low<=high){
            int mid=low+(high-low)/2;
            if(c[mid]<b[mid]){
                low=mid+1;
            }else high=mid-1;
        }

        int sum2=0;
        fr(i,0,r-l){
            if(i<=high) sum2+=c[i];
            else sum2+=b[i];
        }
        sum=min(sum,sum2);   
    }

    cout<<sum<<"\n";
    arr.rs(0,0);
    a.rs(0,0);
    b.rs(0,0);
    c.rs(0,0);
}
 
int32_t main(){
 
    // ios_base::sync_with_stdio(false); 
    // cin.tie(NULL);
 
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++){
        main1();
    }
 
   return 0;
}

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

using namespace std; 

int main(){

	int t;

	cin>>t;

	while(t--){

		long long n,l,r;

		cin>>n>>l>>r;

		long long arr[n+1],brr[n+1];

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

			cin>>arr[i];

			brr[i]=arr[i];

		}

		sort(arr+l,arr+n+1);

		sort(brr+1,brr+r+1);

		long long count=r-l;

		long long sum1=0,sum2=0;

		for(int i=l;i<=l+count;i++){

			sum1+=arr[i];

		}

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

			sum2+=brr[i];

		}

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

	}

	return 0;

}