Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;



#define ff first

#define ss second

#define int long long

#define pb push_back

#define mp make_pair

#define pii pair<int, int>

#define vi vector<int>

#define mii map<int, int>

#define pqb priority_queue<int>

#define pqs priority_queue<int, vi, greater<int>>

#define setbits(x) __builtin_popcountll(x)

#define zrobits(x) __builtin_ctzll(x)

#define mod 100000007

#define inf 1e18

#define ps(x, y) fixed << setprecision(y) << x

#define mk(arr, n, type) type *arr = new type[n]

#define w(x)  \

    int x;    \

    cin >> x; \

    while (x--)



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

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;



void c_p_c()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

#ifndef ONLINE_JUDGE

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

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

#endif

}



int32_t main()

{

    c_p_c();

    w(x)

    {

        int n;

        int l;

        int r;

        cin >> n >> l >> r;

        vi arr(n);

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

            cin >> arr[i];

        vi left_seg;

        vi right_seg;

        vi seg;

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

        {

            seg.pb(arr[i]);

        }

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

        {

            left_seg.pb(arr[i]);

        }

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

        {

            right_seg.pb(arr[i]);

        }



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

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

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

        vi temp = seg;

        int left = 0;

        int s = seg.size() - 1;

        while (s >= 0 && left < left_seg.size() && left_seg[left] < seg[s])

        {

            seg[s] = left_seg[left];

            s--;

            left++;

        }

        int answer_left = accumulate(seg.begin(), seg.end(), 0LL);

        

        int right = 0;

        s = temp.size() - 1;

        while (s >= 0 && right < right_seg.size() && right_seg[right] < temp[s])

        {

            temp[s] = right_seg[right];

            s--;

            right++;

        }

        int answer_right = accumulate(temp.begin(), temp.end(), 0LL);

        int final_answer = min(answer_left, answer_right);

        

        cout << final_answer << endl;

    }

    return 0;

}



Code 2:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 100000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n]
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    c_p_c();
    w(x)
    {
        int n;
        int l;
        int r;
        cin >> n >> l >> r;
        vi arr(n);
        for (int i = 0; i < n; i++)
            cin >> arr[i];
        vi left_seg;
        vi right_seg;
        vi seg;
        for (int i = l - 1; i < r; i++)
        {
            seg.pb(arr[i]);
        }
        for (int i = 0; i < l - 1; i++)
        {
            left_seg.pb(arr[i]);
        }
        for (int i = r; i < n; i++)
        {
            right_seg.pb(arr[i]);
        }

        sort(seg.begin(), seg.end());
        sort(left_seg.begin(), left_seg.end());
        sort(right_seg.begin(), right_seg.end());
        vi temp = seg;
        int left = 0;
        int s = seg.size() - 1;
        while (s >= 0 && left < left_seg.size() && left_seg[left] < seg[s])
        {
            seg[s] = left_seg[left];
            s--;
            left++;
        }
        int answer_left = accumulate(seg.begin(), seg.end(), 0);
        
        int right = 0;
        s = temp.size() - 1;
        while (s >= 0 && right < right_seg.size() && right_seg[right] < temp[s])
        {
            temp[s] = right_seg[right];
            s--;
            right++;
        }
        int answer_right = accumulate(temp.begin(), temp.end(), 0);
        int final_answer = min(answer_left, answer_right);
        
        cout << final_answer << endl;
    }
    return 0;
}


Answer: 1