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

Solution 1 (runtime: 78 ms):
#include <iostream>
#include <cmath>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <deque>
#include <iterator>
#include <queue>
using namespace std;
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

typedef set<int>::iterator Iterator;
void solve()
{
    int n,r,l;
    std::cin>>n>>l>>r;
    l-- ;r--; //base of 0 instead of 1
    int arr[n];
    long long sum=0;
    //priority_queue<int,vector<int>,greater<int>> q;
    priority_queue<int>q1;
    priority_queue<int>q2;
    priority_queue<int,vector<int>,greater<int>>ql;
    priority_queue<int,vector<int>,greater<int>>qr;
    for (int i = 0; i < n; i++)
    {
        std::cin>>arr[i];
        if(i<l)
            ql.push(arr[i]);
        else if(i >= l && i <= r){
            sum+=arr[i];
            q1.push(arr[i]);
            q2.push(arr[i]);
        }
        else
            qr.push(arr[i]);
    }
    long long suml=sum;
    if(!ql.empty() && !q1.empty()){
        while ((q1.top() > ql.top()))
        {
            suml=suml-q1.top()+ql.top();
            q1.pop();
            ql.pop();
            if(ql.empty() || q1.empty())
                break;   
        }
    }
    long long sumr=sum;
    if(!qr.empty() && !q2.empty()){
        while((q2.top() > qr.top()))
        {
            //std::cout<<q2.top()<<"->"<<qr.top()<<endl;
            sumr=sumr-q2.top()+qr.top();
            q2.pop();
            qr.pop();
            if(qr.empty() || q2.empty())
                break;
        }
    }
    if(sumr>suml)
        std::cout<<suml;
    else
        std::cout<<sumr;
}
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
int main()
{
    Fast;
    int test;
    std::cin>>test;    
    while (test--)
    {
        solve();
        std::cout<<endl;   
    } 
    return 0;
}


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

using namespace std;



#define int long long

typedef vector<int> vi;

typedef vector<string> vs;

typedef pair<int, int> pi;

#define F first

#define S second

#define pb push_back

#define mp make_pair

#define Print(a) for(int i = 0; i < a.size(); i++) {cout << a[i] << " ";} cout << endl;

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

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

#define endl "\n"

#define YES cout << "YES\n";

#define NO cout << "NO\n";



int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    /*

    freopen("wtf.in", "r", stdin);

    freopen("wtf.out", "w", stdout);

    */

    int t; cin >> t;

    while (t--) {

        int n, l, r; cin >> n >> l >> r;

        vi a(n);

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

            cin >> a[i];

        }

        l--;

        r--;

        vi b;

        vi c;

        vi m;

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

            b.pb(a[i]);

        }

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

            c.pb(a[i]);

        }

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

            m.pb(a[i]);

        }

        sort(all(b));

        sort(all(c));

        sort(rall(m));

        int res1 = 0;

        for(int i = 0; i < m.size(); i++) {

            res1 += m[i];

        }

        int mn = res1;

        int res2 = res1;

        for(int i = 0; i < min(b.size(), m.size()); i++) {

            res1 -= m[i];

            res1 += b[i];

            mn = min(mn, res1);

        }



        for(int i = 0; i < min(c.size(), m.size()); i++) {

            res2 -= m[i];

            res2 += c[i];

            mn = min(mn, res2);

        }

        cout << mn << endl;



    }

    return 0;

}