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;

using ll = long long;

using ull = unsigned long long;

using ld = long double;

using pii = pair<int, int>;

using pll = pair<ll, ll>;



const int MOD = 1e9 + 7;

const int INF = 1e9;

const ll LINF = 1e18;



#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

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

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

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

#define repr(i, a, b) for (int i = a; i > b; --i)



#define debug(x) cerr << #x << " = " << (x) << endl



//<------------------------------------------------------------------------------------------------>



void solve() {

    ll n, l, r;

    cin >> n >> l >> r;

    vector<int> a(n);

    for(auto& x : a) cin >> x;

    sort(a.begin(), a.end());

    ll k = r-l+1;

    ll ans = 0;

    for(int i = 0; i < k; i++) {

        ans += a[i];

    }

    vector<int> a1, a2, a3;

    for(int i = 0; i < l-1; i++) {

        a1.push_back(a[i]);

    }

    for(int i = l-1; i <r; i++) {

        a2.push_back(a[i]);

    }

    for(int i = r; i < n; i++) {

        a3.push_back(a[i]);

    }

    ans = accumulate(a2.begin(), a2.end(), 0LL);

    sort(a1.begin(), a1.end());

    sort(a2.begin(), a2.end(), greater<int>());

    sort(a3.begin(), a3.end());

    ll ans1 = ans;

    ll ans2 = ans;

    for(int i = 0; i < min(a1.size(), a2.size()); i++) {

        ans1 = min(ans1, ans1 + a1[i] - a2[i]);

    }

    for(int i = 0; i < min(a3.size(), a2.size()); i++) {

        ans2 = min(ans2, ans2 + a3[i] - a2[i]);

    }

    //cout << a1.size() << ' ' << a2.size() << ' ' << a3.size() << endl;

    cout << min(ans1, ans2) << endl;

}



int main() {

    FAST_IO;

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}

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

using namespace std;

using ll = long long;

using ull = unsigned long long;

using ld = long double;

using pii = pair<int, int>;

using pll = pair<ll, ll>;



const int MOD = 1e9 + 7;

const int INF = 1e9;

const ll LINF = 1e18;



#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

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

#define pb push_back

#define mp make_pair

#define fi first

#define se second

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

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

#define repr(i, a, b) for (int i = a; i > b; --i)



#define debug(x) cerr << #x << " = " << (x) << endl



//<------------------------------------------------------------------------------------------------>



void solve() {

    ll n, l, r;

    cin >> n >> l >> r;

    vector<int> a(n);

    for(auto& x : a) cin >> x;

    ll ans = 0;

    vector<int> a1, a2, a3;

    for(int i = 0; i < l-1; i++) {

        a1.push_back(a[i]);

    }

    for(int i = l-1; i <r; i++) {

        a2.push_back(a[i]);

    }

    for(int i = r; i < n; i++) {

        a3.push_back(a[i]);

    }

    ans = accumulate(a2.begin(), a2.end(), 0LL);

    sort(a1.begin(), a1.end());

    sort(a2.begin(), a2.end(), greater<int>());

    sort(a3.begin(), a3.end());

    ll ans1 = ans;

    ll ans2 = ans;

    for(int i = 0; i < min(a1.size(), a2.size()); i++) {

        ans1 = min(ans1, ans1 + a1[i] - a2[i]);

    }

    for(int i = 0; i < min(a3.size(), a2.size()); i++) {

        ans2 = min(ans2, ans2 + a3[i] - a2[i]);

    }

    //cout << a1.size() << ' ' << a2.size() << ' ' << a3.size() << endl;

    cout << min(ans1, ans2) << endl;

}



int main() {

    FAST_IO;

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}