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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
// #include <iostream>
#define ll long long
const ll mod = 1e9 + 7;
// vector<ll> v;

#define iofast()                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);

using namespace std;

ll sod(ll n)
{
    ll m;
    ll sum = 0;
    while (n > 0)
    {
        m = n % 10;
        sum += m;
        n /= 10;
    }
    return sum;
}

int smallestDivisor(int n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (int i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}

int fact(int n)
{
    if (n == 0 || n == 1)
        return 1;
    return (n * fact(n - 1)) % mod;
}

bool check_prime(int n)
{
    for (int i = 2; i < min(n, 50000); i++)
        if (n % i == 0)
            return 0;
    return 1;
}

int highestPowerof2(int n)
{
    int p = (int)log2(n);
    return (int)pow(2, p);
}

// const ll mod1 = 998244353;

void primeFactors(int n)
{
    // Print the number of 2s that divide n
    vector<ll> v;
    while (n % 2 == 0)
    {
        // cout << 2 << " ";
        v.push_back(2);
        n = n / 2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            v.push_back(i);
            // cout << i << " ";
            n = n / i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        v.push_back(n);
    // cout << n << " ";
}

bool isPrime(int n)
{

    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

vector<ll> printDivisors(int n)
{
    vector<ll> v;

    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {

            if (n / i == i)
                v.push_back(i);

            else
                v.push_back(i);
            v.push_back(n / i);
        }
    }
    return v;
}

void printSubsequence(int m, string &l1, string &r1, set<string> &s1, string input, string output)
{

    if (input.empty())
    {
        if (output.size() == m)
        {
            ll flag1 = 0;
            if (flag1 == 0)
            {
                s1.insert(output);
            }
        }
        return;
    }

    printSubsequence(m, l1, r1, s1, input.substr(1), output + input[0]);

    printSubsequence(m, l1, r1, s1, input.substr(1), output);
}

bool sortbyCond(const pair<int, int> &a,
                const pair<int, int> &b)
{
    if (a.first != b.first)
        return (a.first < b.first);
    else
        return (a.second > b.second);
}

int power(long long x, unsigned int y, int p)
{
    int res = 1; // Initialize result

    x = x % p; // Update x if it is more than or
               // equal to p

    if (x == 0)
        return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x) % p;

        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    return a.first * b.second > a.second * b.first;
}

bool cmp1(pair<ll, ll> &a, pair<ll, ll> &b)
{
    return a.first * b.second < a.second * b.first;
}

long long binpow(long long a, long long b)
{
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

long long division(long long a, long long b) // where a is dividend and b is divisor
{
    long long sign = 1;
    if ((a < 0) ^ (b < 0)) // - ^ - = +,+ ^ - = - , - ^ + = - , + ^ + = +
    {
        sign = -1;
    }
    long long m = abs(a);
    long long n = abs(b);
    long long count = 0; // for storing the quotient
    long long temp = 0;
    for (int j = 31; j >= 0; --j)
    {

        if (temp + (n << j) <= m)
        {
            temp += n << j;
            count |= 1L << j;
        }
    }
    if (sign == -1) // when sign is negative
    {
        count = -count;
    }
    return count;
}

ll maxSubArraySum(vector<ll> &a, ll size)
{
    ll max_so_far = LONG_LONG_MIN, max_ending_here = 0;

    for (ll i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}

ll decToBinary(int n)
{
    int binaryNum[32];
    int i = 0;
    while (n > 0)
    {
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }
    string s = "";
    for (int j = i - 1; j >= 0; j--)
        s += binaryNum[j] + '0';

    return stol(s);
}

string convert_31_bit_binary_to_string(ll number)
{
    number &= 0x7FFFFFFF;
    bitset<64> binary(number);
    return binary.to_string();
}

bool isPalindrome(string s)
{
    ll n = s.length();
    for (ll i = 0; i < n / 2; i++)
    {
        if (s[i] != s[n - i - 1])
            return false;
    }

    return true;
}

ll ask(ll x, ll y)
{
    cout << "? " << x << " " << y << endl;
    ll x1;
    cin >> x1;
    return x1;
}

vector<ll> generatePrime(ll n)
{
    vector<ll> prime;
    // prime.push_back(1);

    vector<ll> v(n + 1);

    for (ll i = 2; i <= n; i++)
    {
        if (v[i] == 0)
        {
            prime.push_back(i);
            for (ll j = i * i; j <= n; j += i)
            {
                v[j] = 1;
            }
        }
    }

    return prime;
}

ll grefact(ll n, ll k)
{
    ll flag = 0;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if ((i % 2 == 1 && i >= k) || ((n / i) % 2 == 1 && n / i >= k))
                return 1;
        }
    }

    return 0;
}



int main()
{
    iofast();
    ll t = 1;
    cin >> t;
    while (t--)
    {
        ll n, l, r;
        cin>>n>>l>>r;
        l--;
        vector<ll> v, v1;
        ll ct = 0;
        for (ll i = 0; i < n; i++)
        {
            ll x;
            cin>>x;
            v.push_back(x);
            if(i>=l && i<r)
            {
                ct+=x;
                v1.push_back(x);
            }
        }

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

        ll tp = v1.size()-1;
        ll ans = ct;
        ll ct1 = ct;

        vector<ll> v2;

        for (ll i = 0; i < l; i++)
        {
            v2.push_back(v[i]);
        }

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

        for (ll i = 0; i < l; i++)
        {
            if (tp>=0 && v1[tp]>v2[i])
            {
                ct-=v1[tp];
                ct+=v2[i];
                tp--;
            }
            
        }
        
        
        ans = min(ans, ct);
        ct = ct1;

        v2.clear();

        for (ll i = r; i < n; i++)
        {
            v2.push_back(v[i]);
        }

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

        tp = v1.size();
        tp--;

        for (ll i = 0; i < v2.size(); i++)
        {
            if (tp>=0 && v1[tp]>v2[i])
            {
                ct-=v1[tp];
                ct+=v2[i];
                tp--;
            }
        }


        
        ans = min(ans, ct);

        cout<<ans<<endl;
        



    }
    clock_t tStart = clock();
    cerr << fixed << setprecision(10) << "\nTime Taken: " << (double)(clock() - tStart) / CLOCKS_PER_SEC << endl;

    return 0;
}

Solution 2 (runtime: 78 ms):
#include <bits/stdc++.h>
#define int long long

using namespace std;

typedef pair<int,int> PII;
const int N = 2e5+10, INF = 0x3f3f3f3f3f3f3f3f;
int T, n, x, a[N], l, r;

void solve()
{
	cin >> n >> l >> r;
	for(int i = 1; i<=n; i++)
	{
		cin >> a[i];
	}
	sort(a+1, a+l);
	sort(a+l, a+1+r);
	sort(a+r+1, a+1+n);
	
//	for(int i = 1; i<=n; i++) cout << a[i] << " ";
//	cout << "\n";
	
	int temp1 = 0, temp2 = 0, temp = 0;
	
	for(int i = l; i<=r; i++) temp += a[i];
	
	int R = r, id = 1;
	while(id < l && R >= l)
	{
		if(a[R] > a[id])
		{
			temp1 += a[R] - a[id];
			R--;
			id++;
		} else {
			break;
		}
	}
	
	R = r, id = r+1;
	while(id <= n && R >= l)
	{
		if(a[R] > a[id])
		{
			temp2 += a[R] - a[id];
			R--;
			id++;
		} else {
			break;
		}
	}
//	cout << temp << " " << temp1 << " " << temp2 << "\n";
	cout << temp - max(temp1, temp2) << "\n";
}

/*

9 
1 1 1 5 5 5 5 5 5 1 1

*/

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    T = 1;
    cin >> T;
    while(T--)
    {
    	solve();
	}
    return 0;
}