Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
/*avro28*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define vl vector<ll>
#define pb push_back
#define ff first 
#define ss second
#define dout(x) cerr<<#x<<": "<<x<<"\n";
#define vout(x) cerr<<#x<<": "; \
for (auto &i:x){cerr<<i<<" ";} cerr<<"\n";
#define mout(x)cerr<<#x<<":\n"; \
for (auto &i:x){cerr<<i.ff<<" "<<i.ss<<"\n";}
using namespace std;
using namespace __gnu_pbds;
template<typename T> using oset = tree<T, null_type, 
less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1e9+7, inf=(1LL<<62), N=2e5+5;

// vl g[N], comp;
// bool vis[N];
// ll dp[N][505];

// void dfs(ll node){
//     if (vis[node]) return;
//     vis[node]=1;
//     for (auto &i:g[node]) dfs(i);
//     return;
// }

ll fun(ll id, ll n){
    return 0;
}

void solve(){
    ll n, l, r, sum1=0, sum2=0, mx=-1; 
    cin>>n>>l>>r;
    l--, r--;
    vl a(n), b, c;
    for (ll i=0; i<n; i++){
        cin>>a[i];
    }
    for (ll i=l; i<=r; i++){
        mx=max(mx, a[i]);
    }
    for (ll i=0; i<l; i++){
        if (a[i]<mx) b.pb(a[i]);
    }
    for (ll i=n-1; i>r; i--){
        if (a[i]<mx) c.pb(a[i]);
    }
    sort(a.begin()+l, a.begin()+r+1);
    reverse(a.begin()+l, a.begin()+r+1);
    for (ll i=l; i<=r; i++){
        if (i-l<b.size() && b[i-l]<a[i]) sum1+=b[i-l];
        else sum1+=a[i];
    }
    for (ll i=l; i<=r; i++){
        if (i-l<c.size() && c[i-l]<a[i]) sum2+=c[i-l];
        else sum2+=a[i];
    }
    cout<<min(sum1, sum2)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ll T=1; 
    cin>>T;
    while (T--) solve();
}

Submission (verdict: Accepted):
/*avro28*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define vl vector<ll>
#define pb push_back
#define ff first 
#define ss second
#define dout(x) cerr<<#x<<": "<<x<<"\n";
#define vout(x) cerr<<#x<<": "; \
for (auto &i:x){cerr<<i<<" ";} cerr<<"\n";
#define mout(x)cerr<<#x<<":\n"; \
for (auto &i:x){cerr<<i.ff<<" "<<i.ss<<"\n";}
using namespace std;
using namespace __gnu_pbds;
template<typename T> using oset = tree<T, null_type, 
less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1e9+7, inf=(1LL<<62), N=2e5+5;

// vl g[N], comp;
// bool vis[N];
// ll dp[N][505];

// void dfs(ll node){
//     if (vis[node]) return;
//     vis[node]=1;
//     for (auto &i:g[node]) dfs(i);
//     return;
// }

ll fun(ll id, ll n){
    return 0;
}

void solve(){
    ll n, l, r, sum1=0, sum2=0, mx=-1; 
    cin>>n>>l>>r;
    l--, r--;
    vl a(n), b, c;
    for (ll i=0; i<n; i++){
        cin>>a[i];
    }
    for (ll i=l; i<=r; i++){
        mx=max(mx, a[i]);
    }
    for (ll i=0; i<l; i++){
        b.pb(a[i]);
    }
    for (ll i=n-1; i>r; i--){
        c.pb(a[i]);
    }
    sort(a.begin()+l, a.begin()+r+1);
    reverse(a.begin()+l, a.begin()+r+1);
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    for (ll i=l; i<=r; i++){
        if (i-l<b.size() && b[i-l]<a[i]) sum1+=b[i-l];
        else sum1+=a[i];
    }
    for (ll i=l; i<=r; i++){
        if (i-l<c.size() && c[i-l]<a[i]) sum2+=c[i-l];
        else sum2+=a[i];
    }
    cout<<min(sum1, sum2)<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ll T=1; 
    cin>>T;
    while (T--) solve();
}