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

Solution 1 (runtime: 202 ms):
#include<iostream>

using namespace std;



int arr[200001];

int temp[200001];

void merge ( int *arr, int l1, int r1, int l2, int r2 ) {

	int i = l1, j = l1;

	while ( l1 <= r1 && l2 <= r2 ) {

		temp[i++] = arr[l1] < arr[l2] ? arr[l1++] : arr[l2++];

	}

	while ( l1 <= r1 || l2 <= r2 ) {

		temp[i++] = l1 <= r1 ? arr[l1++] : arr[l2++];

	}

	while ( j <= r2 ) {

		arr[j++] = temp[j];

	}

}

void divide ( int *arr, int l, int r ) {

	if ( l == r ) return;

	divide ( arr, l, ( l + r ) / 2 );

	divide ( arr, ( l + r ) / 2 + 1, r );

	merge ( arr, l, ( l + r ) / 2, ( l + r ) / 2 + 1, r );

}

void solve();



signed main() {



int t; cin>>t;

while(t--) solve();



return 0;



}



void solve() {

	int n, l, r, i, p1, p2;

	long long sum = 0, mn, rem_sum = 0, add_sum = 0; 

	cin >> n >> l >> r;

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

		cin >> arr[i];

		if ( i >= l - 1 && i <= r - 1 ) {

			sum += arr[i]; 

		}

	}

	mn = sum;

	if ( l > 1 ) {

		divide ( arr, 0, l - 2 );

	}

	divide ( arr, l - 1, r - 1 );

	if ( r < n ) {

		divide ( arr, r, n - 1 );

	}

	p1 = r - 1;

	p2 = 0;

	while ( p1 >= l - 1 && p2 < l - 1 ) {

		if ( arr[p1] > arr[p2] ) {

			rem_sum += arr[p1--];

			add_sum += arr[p2++];

		}

		else {

			break;

		}

	}

	mn = sum - rem_sum + add_sum; 

	rem_sum = add_sum = 0;

	p1 = r - 1;

	p2 = r; 

	while ( p1 >= l - 1 && p2 < n ) {

		if ( arr[p1] > arr[p2] ) {

			rem_sum += arr[p1--];

			add_sum += arr[p2++];

		}

		else {

			break;

		}

	}

	mn = mn > sum - rem_sum + add_sum ? sum - rem_sum + add_sum : mn;

	cout << mn << "\n";

}





Solution 2 (runtime: 92 ms):
/**
 *  Author: Abhishek Jha
**/
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)(x).size()
#define ft first
#define sd second
#define pb push_back

typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int, int> pii;typedef vector<pii> vii;typedef vector<vii> vvii;typedef long long ll;
 
const int MOD = 1e9+7;const int INFLL = 1e18+5;const int INF = 1e9;const int maxN = 101;const int maxK = 8001;

void printbit(int x, int len) {string s="\n";while(len--){s=((x%2)?'1':'0')+s;x/=2;} cout<<s;}
 
template<class T>
istream& operator>>(istream&in, vector<T>&v){for (T& x:v) in>>x;return in;}
template<class T>
ostream& operator<<(ostream&out, vector<T>&v){for (T& x:v) out<<x<<' ';cout<<'\n';return out;}

/*---------------------------------------------------------------------------------*/
ll countSetBits(ll n){return __builtin_popcount(n);}

ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}

ll lcm(ll a, ll b){return (a/gcd(a,b)*b);}

bool isPrime(ll n) {if(n==2)    return true;if(n<2)return false;if(n%2 == 0) return false;for(int i=3; i*i<= n; i+= 2)if(n%i==0) return false;return true;}

ll factorial(ll n){return (n==1 || n==0) ? 1: n * factorial(n - 1);}

int smallestDivisor(int n){if (n % 2 == 0) return 2;for (int i = 3; i * i <= n; i += 2) {if (n % i == 0) return i;} return n;}

int largestDivisor(int n){return n/smallestDivisor(n);} 

ll nCr(ll n, ll r){if(r>n)return 0;long long p = 1, k = 1;if(n - r < r)r = n - r;if (r != 0) { while (r) {p *= n;k *= r;ll m = __gcd(p, k);p /= m;k /= m;n--;r--;}}else  p = 1;return p;}
/*------------------------------------------------------------------------------------------------------------------*/

void solve(){
    ll n,l,r;
    cin>>n>>l>>r;
    vi a(n);
    cin>>a;
    vi b;
    vi c;
    for(int i=0;i<=r-1;i++){
        b.push_back(a[i]);
    }
    for(int i=l-1;i<n;i++){
        c.push_back(a[i]);
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll bans = 0;
    ll cans = 0;
    for(int i=0;i<=r-l;i++){
        bans += b[i];
        cans += c[i];
    }
    cout<<min(bans,cans)<<endl;
    
}

/*------------------------------------------------------------------------------------------------------------------*/

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t=1, i = 1;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}