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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
void solve() 
{
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
 
   
    vector<ll> bl(v.begin() + 1, v.begin() + l);  // Before l
    vector<ll> br(v.begin() + r + 1, v.end());    // After r
    vector<ll> need(v.begin() + l, v.begin() + r + 1);  // Between l and r
 
    sort(bl.begin(), bl.end());
    sort(br.begin(), br.end());
    sort(need.begin(), need.end());
 
 
    ll ans1 = 0, ans2 = 0;
    ll sl = 0, sn = 0;
    ll k = r - l + 1;
 
  
    while (k--) {
        if (sl < bl.size() && (sn >= need.size() || bl[sl] <= need[sn])) {
            ans1 += bl[sl++];
        } else {
            ans1 += need[sn++];
        }
    }
 
    k = r - l + 1;
    ll sr = 0;
    sn = 0;
 
  
    while (k--) {
        if (sr < br.size() && (sn >= need.size() || br[sr] <= need[sn])) {
            ans2 += br[sr++];
        } else {
            ans2 += need[sn++];
        }
    }
 
    cout << min(ans1, ans2) << endl;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int t;
    cin >> t;
    while (t--) solve();
 
    return 0;
}

Solution 2 (runtime: 233 ms):
import java.util.*;



public class SubsequenceUpdate{

    public static void main(String[] args) throws Exception{

        Scanner sc = new Scanner(System.in);

        int tc = sc.nextInt();

        int n;

        int l;

        int r;

        int[] la;

        int[] lr;

        int[] ra;

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

            n = sc.nextInt();

            l = sc.nextInt();

            r = sc.nextInt();

            int[] arr = new int[n];

            la = new int[l-1];

            lr = new int[r-l+1];

            ra = new int[n-r];

            int ai = 0;

            int ar = 0;

            int aa = 0;

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

                if(j < l-1){

                    la[ai] = sc.nextInt();

                    ai++;

                }

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

                    lr[ar] = sc.nextInt();

                    ar++;

                }

                if(j > r-1){

                    ra[aa] = sc.nextInt();

                    aa++;

                }

            }

            Arrays.sort(la);

            Arrays.sort(lr);

            Arrays.sort(ra);

            //setup

            if(l == 1 && r == n){

                int sum = 0;

                for(int j = 0; j < la.length; j++){

                    sum += la[j];

                }

                for(int j = 0; j < lr.length; j++){

                    sum += lr[j];

                }

                for(int j = 0; j < ra.length; j++){

                    sum += ra[j];

                }

                System.out.println(sum);

            } else {

                int sum1 = 0;

                int comp1 = lr.length-1;

                if(l != 1){

                    for(int j = 0; j < la.length; j++){

                        if(comp1 < 0){

                            break;

                        }

                        if(la[j] < lr[comp1]){

                            sum1+=la[j];

                            comp1--;

                        } else {

                            sum1+=lr[comp1];

                            comp1--;

                        }

                    }

                    if(comp1 >= 0){

                        for(int j = comp1; j >=0; j--){

                            sum1+=lr[j];

                        }

                    }

                } else {

                    sum1 = Integer.MAX_VALUE;

                }

                int sum2 = 0;

                int comp2 = lr.length-1;

                if(r != n){

                    for(int j = 0; j < ra.length; j++){

                        if(comp2 < 0){

                            break;

                        }

                        if(ra[j] < lr[comp2]){

                            sum2+=ra[j];

                            comp2--;

                        } else {

                            sum2+=lr[comp2];

                            comp2--;

                        }

                    }

                    if(comp2 >= 0){

                        for(int j = comp2; j >=0; j--){

                            sum2+=lr[j];

                        }

                    }

                } else {

                    sum2 = Integer.MAX_VALUE;

                }

                System.out.println(Math.min(sum1, sum2));

            }  

        }

    }

    

}