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

Previous submission (verdict: Wrong answer on test 2):
﻿#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stdexcept>
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// using ul = __int128;
using dle = double;
using dlle = long double;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pdle = pair<double, double>;
using pdlle = pair<long double, long double>;
using ull = unsigned long long;

using vc = vector<char>;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;

using vvc = vector<vector<char>>;
using vvb = vector<vector<bool>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvpi = vector<vector<pair<int, int>>>;
using vvpl = vector<vector<pair<ll, ll>>>;

using vh = unordered_set<ll>;
using vhm = unordered_map<ll, ll>;

const int INFi = 2e9;
const long long INF = 9e18;
const long long MOD = 1050000011;
const long long MMOD = 4611686018427387904;
const long double _PI = 3.14159265358979323846;
mt19937 rnd(time(0));
mt19937_64 rnd64(time(0));

void solut() {
    ll n, l, r;

    cin >> n >> l >> r;
    --l; --r;

    vl mas(n);

    for (int i = 0; i < n; i++) cin >> mas[i];

    vl stin;

    ll res = 0;
    for (int i = l; i <= r; i++) {
        res += mas[i];
        stin.push_back(mas[i]);
    }
    ll sum = res;

    {
        ll cu = res;
        vl st;
        for (int i = 0; i < l; i++) {
            st.push_back(mas[i]);
        }

        sort(stin.rbegin(), stin.rend());
        sort(st.begin(), st.end());

        ll l1 = 0, l2 = 0;
        while (l2 < st.size() && l1 < stin.size() && stin[l1] > st[l2]) {
            cu -= stin[l1] - st[l2];
            ++l1; ++l2;
        }

        res = min(res, cu);
    }
    {
        ll cu = res;
        vl st;
        for (int i = r + 1; i < n; i++) {
            st.push_back(mas[i]);
        }

        sort(stin.rbegin(), stin.rend());
        sort(st.begin(), st.end());

        ll l1 = 0, l2 = 0;
        while (l2 < st.size() && l1 < stin.size() && stin[l1] > st[l2]) {
            cu -= stin[l1] - st[l2];
            ++l1; ++l2;
        }

        res = min(res, cu);
    }

    cout << res << "\n";
}

// ADMIN NE BANb PLZ
int main() {
    //cin.sync_with_stdio(false);
    //cin.tie(0);
    ll t = 1;
    cin >> t;

    while (t--) {
        solut();
    }
}


Submission (verdict: Accepted):
﻿#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stdexcept>
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

// using ul = __int128;
using dle = double;
using dlle = long double;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pdle = pair<double, double>;
using pdlle = pair<long double, long double>;
using ull = unsigned long long;

using vc = vector<char>;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;

using vvc = vector<vector<char>>;
using vvb = vector<vector<bool>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvpi = vector<vector<pair<int, int>>>;
using vvpl = vector<vector<pair<ll, ll>>>;

using vh = unordered_set<ll>;
using vhm = unordered_map<ll, ll>;

const int INFi = 2e9;
const long long INF = 9e18;
const long long MOD = 1050000011;
const long long MMOD = 4611686018427387904;
const long double _PI = 3.14159265358979323846;
mt19937 rnd(time(0));
mt19937_64 rnd64(time(0));

void solut() {
    ll n, l, r;

    cin >> n >> l >> r;
    --l; --r;

    vl mas(n);

    for (int i = 0; i < n; i++) cin >> mas[i];

    vl stin;

    ll res = 0;
    for (int i = l; i <= r; i++) {
        res += mas[i];
        stin.push_back(mas[i]);
    }
    ll sum = res;

    {
        ll cu = sum;
        vl st;
        for (int i = 0; i < l; i++) {
            st.push_back(mas[i]);
        }

        sort(stin.rbegin(), stin.rend());
        sort(st.begin(), st.end());

        ll l1 = 0, l2 = 0;
        while (l2 < st.size() && l1 < stin.size() && stin[l1] > st[l2]) {
            cu -= stin[l1] - st[l2];
            ++l1; ++l2;
        }

        res = min(res, cu);
    }
    {
        ll cu = sum;
        vl st;
        for (int i = r + 1; i < n; i++) {
            st.push_back(mas[i]);
        }

        sort(stin.rbegin(), stin.rend());
        sort(st.begin(), st.end());

        ll l1 = 0, l2 = 0;
        while (l2 < st.size() && l1 < stin.size() && stin[l1] > st[l2]) {
            cu -= stin[l1] - st[l2];
            ++l1; ++l2;
        }

        res = min(res, cu);
    }

    cout << res << "\n";
}

// ADMIN NE BANb PLZ
int main() {
    //cin.sync_with_stdio(false);
    //cin.tie(0);
    ll t = 1;
    cin >> t;

    while (t--) {
        solut();
    }
}