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

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <functional>

#include <utility>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <chrono>

#include <random>

#include <bitset>

#include <cmath>

#include <ranges>

#include <unordered_set>



using namespace std;



typedef long long llong;

typedef unsigned long long ull;

typedef long double ldouble;

typedef pair<int, int> pint;

typedef pair<llong, llong> plong;



#define flr(iter, first, last) for(int iter = first; iter <= last; iter++)

#define frl(iter, last, first) for(int iter = last; iter >= first; iter--)

#define fir(iter, limit) for(int iter = 0; iter < limit; iter++)



#ifdef LOCAL_JUDGE

#define clockinit time_t __clockStart = 0, __clockEnd = 0;

#define clockstart __clockStart = clock();

#define clockstop __clockEnd = clock();

#define clocktime (__clockEnd - __clockStart)

void print_clock_time(time_t clockTime)

{

    cout << "Time elapsed: " << clockTime << " ticks" << endl;

}

#else

#define clockinit

#define clockstart

#define clockstop

#define clocktime

#define print_clock_time(clockTime)

#endif /* ONLINE_JUDGE */



#pragma region quick_snippets



template<class _T>

vector<_T> read_vector(int length, int shift = 0)

{

    vector<_T> v(shift + length);



    for (int i = 0; i < shift; i++)

    {

        v[i] = (_T)0;

    }



    for (int i = shift; i < shift + length; i++)

    {

        cin >> v[i];

    }



    return v;

}



void flush_out()

{

    fflush(stdout);

}



#pragma endregion



const ldouble math_pi_l = acosl(-1.0);

const ldouble math_pi = acos(-1.0);



template<class _T, auto modulo>

struct mint

{

    //llong _T value;

};



//#define GEN_TEST

int main()

{

#ifdef LOCAL_JUDGE



#ifndef GEN_TEST



    freopen("input.txt", "rb", stdin);

    freopen("output.txt", "wb", stdout);



#else



    freopen("input.txt", "wb", stdout);



    int tst = 100000;



    srand(time(0));



    cout << tst << endl;



    for (int i = 0; i < tst; i++)

    {

        cout << i + 1 << endl;

    }



    cout << endl;



    return 0;



#endif /* GEN_TEST */



#endif /* LOCAL_JUDGE */



    clockinit;

    clockstart;



    std::cin.tie(0);

    std::ios_base::sync_with_stdio(0);



    //#define NO_TESTS



    int t;

#if defined(NO_TESTS) && !defined(LOCAL_JUDGE)

    t = 1;

#else

    cin >> t;

#endif



    for (int test = 0; test < t; test++)

    {

        llong n, l, r;

        cin >> n >> l >> r;



        auto a = read_vector<llong>(n);



        vector<llong> vl, vm, vr;



        llong sum = 0;



        fir(i, l) vl.push_back(a[i]);

        flr(i, l, r) { sum += a[i]; vm.push_back(a[i]); }

        flr(i, r + 1, n - 1) vr.push_back(a[i]);



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

        sort(vm.begin(), vm.end(), [&](llong x, llong y) {return x > y; });

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



        auto f = [&](vector<llong> vd, vector<llong> vu)

        {

            llong diff = 0;

            int i = 0;



            while (i < min(vd.size(), vu.size()) && vd[i] < vu[i])

            {

                diff += vd[i] - vu[i];

                i++;

            }



            return diff;

        };



        cout << sum + max(f(vl, vm), f(vr, vm)) << endl;

    }



    clockstop;

    print_clock_time(clocktime);



    return 0;

}

Submission (verdict: Wrong answer on test 1):
#include <iostream>

#include <iomanip>

#include <algorithm>

#include <functional>

#include <utility>

#include <cstring>

#include <string>

#include <vector>

#include <queue>

#include <stack>

#include <map>

#include <set>

#include <chrono>

#include <random>

#include <bitset>

#include <cmath>

#include <ranges>

#include <unordered_set>



using namespace std;



typedef long long llong;

typedef unsigned long long ull;

typedef long double ldouble;

typedef pair<int, int> pint;

typedef pair<llong, llong> plong;



#define flr(iter, first, last) for(int iter = first; iter <= last; iter++)

#define frl(iter, last, first) for(int iter = last; iter >= first; iter--)

#define fir(iter, limit) for(int iter = 0; iter < limit; iter++)



#ifdef LOCAL_JUDGE

#define clockinit time_t __clockStart = 0, __clockEnd = 0;

#define clockstart __clockStart = clock();

#define clockstop __clockEnd = clock();

#define clocktime (__clockEnd - __clockStart)

void print_clock_time(time_t clockTime)

{

    cout << "Time elapsed: " << clockTime << " ticks" << endl;

}

#else

#define clockinit

#define clockstart

#define clockstop

#define clocktime

#define print_clock_time(clockTime)

#endif /* ONLINE_JUDGE */



#pragma region quick_snippets



template<class _T>

vector<_T> read_vector(int length, int shift = 0)

{

    vector<_T> v(shift + length);



    for (int i = 0; i < shift; i++)

    {

        v[i] = (_T)0;

    }



    for (int i = shift; i < shift + length; i++)

    {

        cin >> v[i];

    }



    return v;

}



void flush_out()

{

    fflush(stdout);

}



#pragma endregion



const ldouble math_pi_l = acosl(-1.0);

const ldouble math_pi = acos(-1.0);



template<class _T, auto modulo>

struct mint

{

    //llong _T value;

};



//#define GEN_TEST

int main()

{

#ifdef LOCAL_JUDGE



#ifndef GEN_TEST



    freopen("input.txt", "rb", stdin);

    freopen("output.txt", "wb", stdout);



#else



    freopen("input.txt", "wb", stdout);



    int tst = 100000;



    srand(time(0));



    cout << tst << endl;



    for (int i = 0; i < tst; i++)

    {

        cout << i + 1 << endl;

    }



    cout << endl;



    return 0;



#endif /* GEN_TEST */



#endif /* LOCAL_JUDGE */



    clockinit;

    clockstart;



    std::cin.tie(0);

    std::ios_base::sync_with_stdio(0);



    //#define NO_TESTS



    int t;

#if defined(NO_TESTS) && !defined(LOCAL_JUDGE)

    t = 1;

#else

    cin >> t;

#endif



    for (int test = 0; test < t; test++)

    {

        llong n, l, r;

        cin >> n >> l >> r;

        l--; r--;



        auto a = read_vector<llong>(n);



        vector<llong> vl, vm, vr;



        llong sum = 0;



        fir(i, l) vl.push_back(a[i]);

        flr(i, l, r) { sum += a[i]; vm.push_back(a[i]); }

        flr(i, r + 1, n - 1) vr.push_back(a[i]);



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

        sort(vm.begin(), vm.end(), [&](llong x, llong y) {return x > y; });

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



        auto f = [&](vector<llong> vd, vector<llong> vu)

        {

            llong diff = 0;

            int i = 0;



            while (i < min(vd.size(), vu.size()) && vd[i] < vu[i])

            {

                diff += vd[i] - vu[i];

                i++;

            }



            return diff;

        };



        cout << sum + max(f(vl, vm), f(vr, vm)) << endl;

    }



    clockstop;

    print_clock_time(clocktime);



    return 0;

}