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

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 4e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN];

void Read(vector<int>& v){

    for (int& x : v) cin >> x;
    sort(all(v));
}

ll Calc(int m, vector<int> a, vector<int> b){

    for (int i = 1; i < a.size(); i++) a[i] += a[i-1];
    for (int i = 1; i < b.size(); i++) b[i] += b[i-1];
    ll ans = LINF;
    if (a.size() >= m) smin(ans, (ll)a[m-1]);
    if (b.size() >= m) smin(ans, (ll)b[m-1]);
    for (int i = max(m-1-(int)b.size(), 0); i < min((int)a.size(), m-1); i++)
        smin(ans, (ll)a[i] + b[m-i-2]);
    return ans;
}

void Solve(){

    cin >> n; ri(l); ri(r);
    l--; r--;
    vector<int> a(l), b(r-l+1), c(n-r-1);
    Read(a); Read(b); Read(c);
    cout << min(Calc(r-l+1, a, b), Calc(r-l+1, b, c)) << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;

    int t = 1;
    cin >> t;
    while (t--)
        Solve();

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>



#define ll long long

#define ld long double

#define pb push_back

#define fi first

#define se second

#define en '\n'

#define sp ' '

#define tb '\t'

#define ri(n) int n; cin >> n

#define rl(n) ll n; cin >> n

#define rs(s) string s; cin >> s

#define rc(c) char c; cin >> c

#define rv(v) for (auto &x : v) cin >> x

#define pven(v) for (auto x : v) cout << x << en

#define pv(v) for (auto x : v) cout << x << sp; cout << en

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

#define rall(v) v.rbegin(), v.rend()

#define yes cout << "YES" << en

#define no cout << "NO" << en

#define smin(a, b) a = min(a, b)

#define smax(a, b) a = max(a, b)

#define ssort(a, b) if (a < b) swap(a, b)

#define bitcnt(a) (__builtin_popcountll(a))

#define bithigh(a) (63-__builtin_clzll(a))

#define lg bithigh

#define highpow(a) (1LL << (ll)lg(a))



using namespace std;



const ll LINF = 4e18;

const int mxN = 1e6+10, INF = 2e9;

ll n, m, a[mxN];



void Read(vector<int>& v){



    for (int& x : v) cin >> x;

    sort(all(v));

}



ll Calc(vector<int> a, vector<int> b){



    int i = a.size()-1, j = -1;

    while (i >= 0 && j+1 < b.size() && a[i] > b[j+1]) i--, j++;

    ll sum = 0;

    for (int k = 0; k <= i; k++) sum += a[k];

    for (int k = 0; k <= j; k++) sum += b[k];

    return sum;

}



void Solve(){



    cin >> n; ri(l); ri(r);

    l--; r--;

    vector<int> a(l), b(r-l+1), c(n-r-1);

    Read(a); Read(b); Read(c);

    cout << min(Calc(b, a), Calc(b, c)) << en;

}



int main(){



    ios::sync_with_stdio(false);

    cin.tie(0); cout.tie(0); cerr.tie(0);

    cout << setprecision(12) << fixed;

    cerr << setprecision(12) << fixed;



    int t = 1;

    cin >> t;

    while (t--)

        Solve();



    return 0;

}