Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

#define int long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
template<class T> using vv = vector<vector<T>>;

#define pb emplace_back
#define mkp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define siz(v) (int)(size(v))

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
#define rept(a) rep(_, 1, a)

#define watch(x) cout << (#x) << ':' << (x) << '\n';
#define watch2(x, y) cout << (#x) << ':' << (x) << ',' << (#y) << ':' << (y) << '\n';

template<class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os << '{' << p.first << ',' << p.second << '}';
}
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	for (auto &x : v) os << x << ' ';
	return os;
}

const int inf = 1e9;
const ll llinf = 4e18;

void orz()
{
    int n, l, r;
    cin >> n >> l >> r;
    l--, r--;
    vi a, b, c;
    rep(i, 0, l-1){
        int x; cin >> x;
        a.pb(x);
    }
    rep(i, l, r){
        int x; cin >> x;
        b.pb(x);
    }
    rep(i, r+1, n-1){
        int x; cin >> x;
        c.pb(x);
    }
    
    sort(all(a));
    sort(all(b), greater<int>());
    sort(all(c));

    int red = 0;
    rep(i, 0, min(siz(a), siz(b))-1){
        if (a[i] < b[i]) red += b[i]-a[i];
    }

    int red2 = 0;
    rep(i, 0, min(siz(c), siz(b))-1){
        if (c[i] < b[i]) red += b[i]-c[i];
    }

    int ans = accumulate(all(b), 0ll)-max(red, red2);

    cout << ans << '\n';
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin.exceptions(cin.failbit);

    int t = 1; cin >> t;
    while (t--) orz();
}


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

#define int long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
template<class T> using vv = vector<vector<T>>;

#define pb emplace_back
#define mkp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define siz(v) (int)(size(v))

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
#define rept(a) rep(_, 1, a)

#define watch(x) cout << (#x) << ':' << (x) << '\n';
#define watch2(x, y) cout << (#x) << ':' << (x) << ',' << (#y) << ':' << (y) << '\n';

template<class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os << '{' << p.first << ',' << p.second << '}';
}
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	for (auto &x : v) os << x << ' ';
	return os;
}

const int inf = 1e9;
const ll llinf = 4e18;

void orz()
{
    int n, l, r;
    cin >> n >> l >> r;
    l--, r--;
    vi a, b, c;
    rep(i, 0, l-1){
        int x; cin >> x;
        a.pb(x);
    }
    rep(i, l, r){
        int x; cin >> x;
        b.pb(x);
    }
    rep(i, r+1, n-1){
        int x; cin >> x;
        c.pb(x);
    }
    
    sort(all(a));
    sort(all(b), greater<int>());
    sort(all(c));

    int red = 0;
    rep(i, 0, min(siz(a), siz(b))-1){
        if (a[i] < b[i]) red += b[i]-a[i];
        else break;
    }

    int red2 = 0;
    rep(i, 0, min(siz(c), siz(b))-1){
        if (c[i] < b[i]) red += b[i]-c[i];
        else break;
    }

    int ans = accumulate(all(b), 0ll)-max(red, red2);
    
    if (ans <= 0){
        cout << a << b << c << '\n';
        watch2(l, r)
    }

    cout << ans << '\n';
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin.exceptions(cin.failbit);

    int t = 1; cin >> t;
    while (t--) orz();
}