Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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



using namespace std;



#define pb push_back

#define F first

#define S second



#define MOD 1000000007



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

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

#define FOR(i, a, b) for(int i = a; i < (b); i++)

#define YES(con) if (con) { cout << "YES\n"; return; }

#define NO(con) if (con) { cout << "NO\n"; return; }

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



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef vector<unsigned long long> vull;



const char nl = '\n';

const ld PI = acos(-1.0);

const int INF32 = int(1e9) + int(1e8) + int(1e7) + int(1e6) + int(1e5);

const int64_t INF64 = int64_t(1e18) + int64_t(1e17) + int64_t(1e16);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



template<typename... T>void read(T&... args) {((cin >> args), ...);}

template<typename... T>void print(T&&... args) {((cout << args ), ...);}



struct custom_hash {

    static uint64_t splitmix64(uint64_t x) {

        x += 0x9e3779b97f4a7c15;

        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;

        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;

        return x ^ (x >> 31);

    }

    size_t operator()(uint64_t x) const {

        static const uint64_t FIXED_RANDOM =

                chrono::steady_clock::now().time_since_epoch().count();

        return splitmix64(x + FIXED_RANDOM);

    }

};



ll inv(ll i, ll m) {

    return (i <= 1 ? 1 : m - (m / i) * inv(m % i, m) % m);

}



template <typename T>

void readv(vector<T>& v) {

    for (auto& el : v) cin >> el;

}



template<typename T>

void outv(vector<T>& v) {

    for (int i = 0; i < (T)v.size(); i++) {

        if (i != (T)v.size() - 1) cout << v[i] << ' ';

        else cout << v[i];

    }

}



template <typename T>

void printColl(T& coll) {

    cout << '\n';

    for (const auto& el : coll) cout << el << ' ';

    cout << '\n';

}



void solve() {

    ll n, l, r;

    cin >> n >> l >> r;

    --l, --r;

    vll v(n), vv, zz;

    FOR (i, 0, n) {

        cin >> v[i];

        if (i < l || i > r) {

            zz.pb(v[i]);

        }

    }

    

    ll val = max(n - r - 1, l);

    FOR (i, l, r + 1) {

        vv.pb(v[i]);

    }

    

    sort(all(zz));

    sort(rall(vv));

    

    ll i = 0, ans = 0, j = 0;

    for (int i = 0; i < vv.size(); i++) {

        if (val) {

            if (zz[j] < vv[i]) {

                ans += zz[j++];

            } else {

                ans += vv[i];

            }

            val--;

        } else {

            ans += vv[i];

        }

    }

    

    print(ans, nl);

}



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    cout << fixed << setprecision(12);



    int t;

    cin >> t;



    while (t--) solve();



    return 0;

}

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



using namespace std;



#define pb push_back

#define F first

#define S second



#define MOD 1000000007



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

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

#define FOR(i, a, b) for(int i = a; i < (b); i++)

#define YES(con) if (con) { cout << "YES\n"; return; }

#define NO(con) if (con) { cout << "NO\n"; return; }

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



typedef long long ll;

typedef unsigned long long ull;

typedef long double ld;

typedef vector<int> vi;

typedef vector<long long> vll;

typedef vector<unsigned long long> vull;



const char nl = '\n';

const ld PI = acos(-1.0);

const int INF32 = int(1e9) + int(1e8) + int(1e7) + int(1e6) + int(1e5);

const int64_t INF64 = int64_t(1e18) + int64_t(1e17) + int64_t(1e16);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



template<typename... T>void read(T&... args) {((cin >> args), ...);}

template<typename... T>void print(T&&... args) {((cout << args ), ...);}



struct custom_hash {

    static uint64_t splitmix64(uint64_t x) {

        x += 0x9e3779b97f4a7c15;

        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;

        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;

        return x ^ (x >> 31);

    }

    size_t operator()(uint64_t x) const {

        static const uint64_t FIXED_RANDOM =

                chrono::steady_clock::now().time_since_epoch().count();

        return splitmix64(x + FIXED_RANDOM);

    }

};



ll inv(ll i, ll m) {

    return (i <= 1 ? 1 : m - (m / i) * inv(m % i, m) % m);

}



template <typename T>

void readv(vector<T>& v) {

    for (auto& el : v) cin >> el;

}



template<typename T>

void outv(vector<T>& v) {

    for (int i = 0; i < (T)v.size(); i++) {

        if (i != (T)v.size() - 1) cout << v[i] << ' ';

        else cout << v[i];

    }

}



template <typename T>

void printColl(T& coll) {

    cout << '\n';

    for (const auto& el : coll) cout << el << ' ';

    cout << '\n';

}



void solve() {

    ll n, l, r;

    cin >> n >> l >> r;

    --l, --r;

    vll v(n), vv, zz;

    FOR (i, 0, n) {

        cin >> v[i];

        if (i < l || i > r) {

            zz.pb(v[i]);

        }

    }

    

    // printColl(zz);

    

    ll val = max(n - r - 1, l);

    FOR (i, l, r + 1) {

        vv.pb(v[i]);

    }

    

    // printColl(vv);

    

    sort(all(zz));

    sort(rall(vv));

    

    ll ans = 0, j = 0;

    for (int i = 0; i < vv.size(); i++) {

        if (val && zz[j] < vv[i]) {

            ans += zz[j++];

            val--;

        } else {

            ans += vv[i];

        }

    }

    

    ll ans2 = 0;

    j = 0;

    val = min(n - r - 1, l);

    for (int i = 0; i < vv.size(); i++) {

        if (val && zz[j] < vv[i]) {

            ans2 += zz[j++];

            val--;

        } else {

            ans2 += vv[i];

        }

    }

    

    print(min(ans, ans2), nl);

}



signed main() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    cout << fixed << setprecision(12);



    int t;

    cin >> t;



    while (t--) solve();



    return 0;

}