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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

void solve()
{

    int n, l, r;
    cin >> n >> l >> r;
    vl v(n);
    for (auto &i : v)
        cin >> i;
    l--, r--;
    sort(v.begin(), v.begin() + l,greater<>());
    sort(v.begin() + r + 1, v.end());

    ll mn = 0;
    for (int i = l; i <= r; i++)
        mn += v[i];
    ll S = mn;
    if (r + 1 != n)
    {
        sort(v.begin() + l, v.begin() + r + 1);
        int i = r + 1;
        int j = r;
        ll s = S;
        ll sm = 0;
        while (j >= l and i < n)
        {
            s -= v[j];
            sm += v[i];
            mn = min(mn, s + sm);
            j--;
            i++;
        }
    }
    // dbg2(mn, S);
    if (l != 0)
    {

        // sort(v.begin() + l, v.begin() + r + 1);

        ll sm = S;
        int i = l - 1;
        ll ss = 0;
        while (i >= 0 and r >= l)
        {
            ss += v[i];
            sm -= v[r];
            mn = min(mn, ss + sm);
            i--;
            r--;
        }
    }
    cout << mn << endl;
}

int main()
{
    IOS;
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
//                                       Sk Najir
#ifndef ONLINE_JUDGE
#include "db.hpp"
#else
#define dbg(x)
#define dbg2(x, y)
#define dbg3(x, y, z)
#endif
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);

// pre_define
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

// shortcut type
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;

// Constants
const int MOD = 1e9 + 7;

void solve()
{
    multiset<ll> pre, cur, suf;
    int n, l, r;
    cin >> n >> l >> r;
    ll x;
    l--, r--;
    ll S = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        if (i < l)
            pre.insert(x);
        else if (i > r)
            suf.insert(x);
        else
            cur.insert(x), S += x;
    }
    // dbg(pre);
    // dbg(cur);
    // dbg(suf);
    multiset<ll> tem = cur;
    ll sm = 0, s = S;
    ll mn = S;
    while (!tem.empty() and !suf.empty())
    {
        s -= *tem.rbegin();
        tem.erase(prev(tem.end()));
        sm += *suf.begin();
        suf.erase(suf.begin());
        mn = min(mn, sm + s);
    }
    tem = cur;
    suf = pre;
    sm = 0;
    s = S;
    while (!tem.empty() and !suf.empty())
    {
        s -= *tem.rbegin();
        tem.erase(prev(tem.end()));
        sm += *suf.begin();
        suf.erase(suf.begin());
        mn = min(mn, sm + s);
    }
    cout << mn << endl;
}

int main()
{
    IOS;
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++)
        solve();
}