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

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

#define endl "\n"
#define ends " "
#define double long double
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<double> cpx;

const int xw[6] = { 1,0,-1,0,1,-1 };
const int yw[6] = { 0,1,0,-1,-1,1 };
const int zw[6] = { 0,0,0,0,1,-1 };

const ll MOD = 1000000007;
const int INF = 0x7f7f7f7f;
const ll LINF = 0x7f7f7f7f7f7f7f7f;
const double PI = acos(-1);
const double eps = 1e-10;
// ----------------------------------------------

int n, l, r;
ll a[101010];

ll solve() {
    ll res, tmp, sum = 0;
    vector<ll>L, M, R;
    // Init


    cin >> n >> l >> r;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];

        if (i < l)L.push_back(a[i]);
        else if (i > r)R.push_back(a[i]);
        else {
            M.push_back(a[i]);
            sum += a[i];
        }
    }
    // Input


    res = sum;
    sort(all(L)); sort(all(M)); sort(all(R));
    reverse(all(M));
    // Sort


    tmp = sum;
    for (int i = 0; i < min(sz(L), sz(M)); i++) {
        if (M[i] <= L[i]) {
            res = min(res, tmp);
            break;
        }
        tmp -= M[i] - L[i];
        res = min(res, tmp);
    }
    
    tmp = sum;
    for (int i = 0; i < min(sz(R), sz(M)); i++) {
        if (M[i] <= R[i]) {
            res = min(res, tmp);
            break;
        }
        tmp -= M[i] - R[i];
        res = min(res, tmp);
    }

    return res;
}

int main() {
    cin.tie(NULL); cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    // Stream Init

    int tt; cin >> tt;
    while (tt--) {
        cout << solve() << endl;
    }

    return 0;
}


Solution 2 (runtime: 93 ms):
#include <algorithm>

#include <array>

#include <iomanip>

#include <iostream>

#include <cmath>

#include <cstdint>

#include <numeric>

#include <map>

#include <set>

#include <string>

#include <vector>



using namespace std;



int64_t min_sum(const vector<int64_t>& lr, const vector<int64_t>& other) {

    int64_t diff = 0;



    for (int i = 0; i < min(lr.size(), other.size()); i++) {

        // cout << "loop: " << other[i] << " " << lr[i] << endl;

        if (other[i] < lr[i]) diff += (lr[i] - other[i]);

    }

    // cout << diff << endl;

    return diff;

}

void solve() {

    // Read input

    int n, l, r;

    cin >> n >> l >> r;

    l--; r--;

    vector<int64_t> a(n);

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

        cin >> a[i];

    }



    // Solve the problem here

    vector<int64_t> lr;

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

        lr.push_back(a[i]);

    }

    sort(lr.begin(), lr.end(), std::greater<int64_t>());



    int64_t sum = accumulate(lr.begin(), lr.end(), int64_t(0));

    // cout << sum << endl;

    vector<int64_t> bl;

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

        bl.push_back(a[i]);

    }

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



    vector<int64_t> ar;

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

        ar.push_back(a[i]);

    }

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



    sum = min(min(sum, sum - min_sum(lr, bl)), sum - min_sum(lr, ar));

    // Print output

    cout << sum << endl;

}



int main() {

    // freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout << setprecision(10);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}