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

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

using namespace std;

int main()

{

    int t;

    cin >> t;

    while(t--)

    {

        int n, l,r;

        cin >> n >> l >> r;

        l-=1;

        r-=1;

        int arr[n];

        vector <long long int> arr1, arr2;

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

        {

            cin >> arr[i];

            if(i<l)

            arr1.push_back(arr[i]);

            else if(i>r)

            arr2.push_back(arr[i]);

            else

            {

                arr1.push_back(arr[i]);

                arr2.push_back(arr[i]);

            }

        }

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

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

        long long int sum1=0, sum2=0;

        for(int i=0;i<r-l+1;i++)

        {

            sum1+=arr1[i];

            sum2+=arr2[i];

        }

        cout << min(sum1, sum2) << endl;

    }

}

Solution 2 (runtime: 93 ms):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while(t--){
        int n, l, r;
        cin >> n >> l >> r;
        vector<long long> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        
        // Compute the original sum over the window [l, r]
        long long base = 0;
        vector<long long> window;
        for (int i = l - 1; i < r; i++){
            base += a[i];
            window.push_back(a[i]);
        }
        // To “drop” as much sum as possible, we want to replace high values.
        // So sort the window values in descending order.
        sort(window.begin(), window.end(), greater<long long>());
        
        // Option 1: Use indices AFTER r (i.e. [r+1, n]) as candidate positions.
        vector<long long> candidateAfter;
        if(r < n){
            for (int i = r; i < n; i++){
                candidateAfter.push_back(a[i]);
            }
            // For improvement we want the smallest values from outside.
            sort(candidateAfter.begin(), candidateAfter.end());
        }
        
        // Option 2: Use indices BEFORE l (i.e. [1, l-1]) as candidate positions.
        vector<long long> candidateBefore;
        if(l > 1){
            for (int i = 0; i < l - 1; i++){
                candidateBefore.push_back(a[i]);
            }
            sort(candidateBefore.begin(), candidateBefore.end());
        }
        
        long long bestImprove = 0;
        
        // Try using candidateAfter.
        int kmax = min((int)window.size(), (int)candidateAfter.size());
        long long sumWindow = 0, sumCand = 0;
        for (int k = 0; k < kmax; k++){
            sumWindow += window[k];          // sum of k largest values in the window
            sumCand += candidateAfter[k];      // sum of k smallest values outside (after r)
            bestImprove = max(bestImprove, sumWindow - sumCand);
        }
        
        // Try using candidateBefore.
        kmax = min((int)window.size(), (int)candidateBefore.size());
        sumWindow = 0;
        sumCand = 0;
        for (int k = 0; k < kmax; k++){
            sumWindow += window[k];          // again, k largest in window
            sumCand += candidateBefore[k];     // k smallest outside (before l)
            bestImprove = max(bestImprove, sumWindow - sumCand);
        }
        
        // The best reversal can reduce the sum by bestImprove.
        long long ans = base - bestImprove;
        cout << ans << "\n";
    }
    return 0;
}