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

Solution 1 (runtime: 93 ms):
#include "bits/stdc++.h"

#define int long long

#define uint unsigned long long

#define vi vector<int>

#define vvi vector<vi >

#define vb vector<bool>

#define vvb vector<vb >

#define fr(i,n) for(int i=0; i<(n); i++)

#define rep(i,a,n) for(int i=(a); i<=(n); i++)

#define nl cout<<"\n"

#define dbg(var) cout<<#var<<"="<<var<<" "

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

#define sz(v) (int)(v.size())

#define srt(v)  sort(v.begin(),v.end())         // sort 

#define mxe(v)  *max_element(v.begin(),v.end())     // find max element in vector

#define mne(v)  *min_element(v.begin(),v.end())     // find min element in vector

#define unq(v)  v.resize(distance(v.begin(), unique(v.begin(), v.end())));

// make sure to sort before applying unique // else only consecutive duplicates would be removed 

#define bin(x,y)  bitset<y>(x) 

using namespace std;

int MOD=1e9+7;      // Hardcoded, directly change from here for functions!







void modadd(int &a , int b) {a=((a%MOD)+(b%MOD))%MOD;}

void modsub(int &a , int b) {a=((a%MOD)-(b%MOD)+MOD)%MOD;}

void modmul(int &a , int b) {a=((a%MOD)*(b%MOD))%MOD;}

// ================================== take ip/op like vector,pairs directly!==================================

template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }

template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }

template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }

template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }

template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }

// ===================================END Of the input module ==========================================





void solve(){

    int n,l,r;

    cin >> n >> l >> r;

    vi arr(n,0),left,right;  

    fr(i,n)cin>>arr[i];

    for(int i=0;i<r;i++)left.push_back(arr[i]);

    for(int i=l-1;i<n;i++)right.push_back(arr[i]);

    srt(left);srt(right);

    int ans=INT_MAX;

    int sum1=0,sum2=0;

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

        sum1+=left[i];

        //cout<<left[i]<<" ";

        sum2+=right[i];

    }

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

    

}



int32_t main()

{

 

 ios_base::sync_with_stdio(false);

 cin.tie(NULL);



    int T = 1;

    cin >> T;

    while (T--)

    {

        solve();

    }

    return 0;

}

Solution 2 (runtime: 77 ms):
// Created by Rishi Sharma (@rishisharmapro) on 07-02-2025 at 18:22
// #include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; r--;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a.begin()+l, a.begin()+r+1);
    if (l > 0) sort(a.begin(), a.begin()+l);
    if (r < n-1) sort(a.begin()+r+1, a.end());


    ll sum = 0;
    for(int i = l; i <= r; i++) {
        sum += a[i];
    }

    // traversing left of the subsequence
    ll leftSum = sum;
    int index = r;
    for(int i = 0; i < l && index >= l; i++) {
        if(a[i] < a[index]) {
            leftSum += a[i];
            leftSum -= a[index];
            index--;
        }
        else break;
    }

    // traversing right of the subsequence
    ll rightSum = sum;
    index = r;
    for(int i = r+1; i < n && index >= l; i++) {
        if(a[i] < a[index]) {
            rightSum += a[i];
            rightSum -= a[index];
            index--;
        }
        else break;
    }

    cout << min(sum, min(leftSum, rightSum)) << endl;
}

int main() {
    // problem: https://codeforces.com/contest/2063/problem/B
    fast_io;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}