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

Solution 1 (runtime: 77 ms):
//******************************************************//
//*                AUTHOR: NAMAN OSTWAL                *//
//******************************************************//
//______________________________________________________________________________________________________//
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
long long int INF = 1e18;
long long int mod = 1e9+7;
const int N = 1e6+7;
vector<bool> isprime(N, true);

inline void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void print(vector<ll>&v) { for(auto it : v) cout<<it<<' '; }
void sort(vector < ll > &v) { sort(v.begin() , v.end()); }
void rsort(vector < ll > &v) { sort(v.begin() , v.end(), greater<int>()); }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
ll lcm(ll a, ll b) { return ((a * b) / (__gcd(a,b))); }

ll bin_expo(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1) {
            ans = (ans * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans % mod;
}

void sieve_of_eratosthenes() {
    isprime[0] = isprime[1] = false;
    for(int i = 2; i<=N; i++) {
        if(isprime[i] == true) {
            for(int j = 2*i; j<=N; j+=i) {
                isprime[j] = false;
            }
        }
    }
}

bool ispal(string s) {
    int n = s.size();
    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[n - i - 1]) {
            return false;
        }
    }
    return true;
}

void DFSUtil(ll node, vector<vector<ll>>& adj, vector<bool>& visited, vector<ll>& dfs) {
    visited[node] = true;
    dfs.push_back(node);
    for (ll neighbor : adj[node]) {
        if (!visited[neighbor]) {
            DFSUtil(neighbor, adj, visited, dfs);
        }
    }
}

void dfs(vector<vector<ll>>& adj, ll n, vector<ll>& dfs) {
    vector<bool> visited(n, false);
    for (ll i = 0; i < n; ++i) {
        if (!visited[i]) {
            DFSUtil(i, adj, visited, dfs);
        }
    }
}

void bfs(vector<vector<ll>>& adj, ll n, vector<ll>& bfs) {
    queue<ll> q;
    vector<bool> visited(n, false);
    visited[0] = true;
    q.push(0);
    while (!q.empty()) {
        ll node = q.front();
        q.pop();
        bfs.push_back(node);
        for (auto it : adj[node]) {
            if (!visited[it]) {
                visited[it] = true;
                q.push(it);
            }
        }
    }
}

int main() {
    fast_io();
    int t;
    cin >> t;
    while (t--) {
        ll n, l, r;
    	cin >> n >> l >> r;
    	vector<ll> a(n);
    	for (int i = 0; i < n; i++) cin >> a[i];
    	l--, r--;
    	ll len = r - l + 1;
    	vector<ll> pre(len + 1, INF), suf(len + 1, INF), mid(len + 1, INF);
    	sort(a.begin(), a.begin() + l);
    	sort(a.begin() + l, a.begin() + r + 1);
    	reverse(a.begin() + l, a.begin() + r + 1);
    	sort(a.begin() + r + 1, a.end());
    	suf[0] = pre[0] = mid[0] = 0;
    	for (int i = 0; i < min(len, l); i++) {
    		pre[i + 1] = pre[i] + a[i];
    	}
    	for(int i = l; i <= r; i++) {
    		mid[i - l + 1] = mid[i - l] + a[i];
    	}
    	for(int i = r + 1; i < min(r + 1 + len, n); i++) {
    		suf[i - r] = suf[i - r - 1] + a[i];
    	}
    	ll ans = 0;
    	for(int i = 1; i <= len; i++) {
    		ans = max(ans, mid[i] - suf[i]);
    		ans = max(ans, mid[i] - pre[i]);
    	}
    	ans = -ans;
    	for(int i = l; i <= r; i++) ans += a[i];
    	cout << ans << "\n";
    }
    return 0;
}

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

using namespace std;



#define ll long long

#define ull unsingned long long

#define lld long double

#define vi vector<int>

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define MOD 1000000007

#define INF 1e18

#define umap unordered_map

#define uset unordered_set

#define b begin

#define e end

#define mp make_pair

#define ff first

#define ss second

#define pb push_back

#define ppb pop_back

#define ln cout<<endl;

#define ifor(i, a, n) for(int i = a; i <= n; i++)

#define rfor(i, n, a) for(int i = n; i >= a; i--)

#define printarr(arr) for(int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) cout<<arr[i]<<" ";

#define debug(x) cout<<#x<<" "; _print(x); cout<<endl;





//debug

void _print(int x){cout<<x;}

void _print(double x){cout<<x;}

void _print(ll x){cout<<x;}

void _print(string x){cout<<x;}

void _print(char x){cout<<x;}

void _print(bool x){cout<<x;}

template<class T> void _print(vector<T> v){cout<<"[ "; for(T i:v){_print(i); cout<<" ";} cout<<" ]";}

template<class T, class V> void _print(vector<pair<T, V>> v){cout<<"[ "; for(pair<T, V> i:v){cout<<"(";_print(i.ff); cout<<", "; _print(i.ss); cout<<") ";} cout<<" ]";}

template<class T> void _print(set<T> v){cout<<"[ "; for(T i:v){_print(i); cout<<" ";} cout<<" ]";}

template<class T> void _print(uset<T> v){cout<<"[ "; for(T i:v){_print(i); cout<<" ";} cout<<" ]";}

template<class T, class V> void _print(pair<T,V> p){cout<<"{"; _print(p.ff); cout<<", "; _print(p.ss); cout<<"}";}

template<class T, class V> void _print(map<T,V> m){cout<<"[ "; for(auto i:m){_print(i); cout<<" ";} cout<<"]";}

template<class T, class V> void _print(umap<T,V> um){cout<<"[ "; for(auto i:um){_print(i); cout<<" ";} cout<<"]";}





int is_prime(int n) {

	ifor(i, 2, sqrt(n)) {

		if(!(n % i)) return 0;

	}

	return 1;

}





const int N = 200000+20;

// vi graph[N];

// int visited[N];



// void dfs(int vertex) {

// 	if(visited[vertex]) return;



// 	visited[vertex] = 1;

// 	for(auto child: graph[vertex]) {

// 		if(visited[child]) continue;

// 		dfs(child);

// 	}

// }





//int arr[N];

//int dp[N];





int is_ok(ll mid, ll arr[], ll n, ll ind, ll curr_sum, ll k) {

    ll rest = arr[n-1] - arr[ind];

    if(curr_sum + mid + rest >= k) {

        return 1;

    }

    return 0;

}







//main

int main() {

	fast_io;

    

    int t;

    cin>>t;



    while(t--) {

        int n, l, r;

        cin>>n>>l>>r;



        int arr[n+1];



        arr[0] = 0;

        ifor(i, 1, n) {

            cin>>arr[i];

        }



        sort(arr+1, arr+l);

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

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



        int arr2[n+1];

        ifor(i, 0, n) arr2[i] = arr[i];

        int temp = r;

        ifor(i, 1, l-1) {

            if(arr2[i] < arr[temp]) {

                swap(arr2[i], arr2[temp]);

                temp--;

            }

        }



        ll ans = 0;



        ifor(i, l, r) {

            ans += arr2[i];

        }



        temp = r;

        ifor(i, r+1, n) {

            if(arr[i] < arr[temp]) {

                swap(arr[i], arr[temp]);

                temp--;

            }

        }



        ll ans2 = 0;

        ifor(i, l, r) {

            ans2 += arr[i];

        }



        cout<<min(ans, ans2)<<endl;



    }





    return 0;

}