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

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

// Fast I/O
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr);

// Aliases for convenience
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using pii = pair<int, int>;

// Constants
const int MOD = 1e9 + 7;
const int INF = INT_MAX;

// Solve function
void solve()
{
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> v(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    vector<int> left;
    vector<int> right;
    vector<int> mid;
    for (int i = 0; i<n ; i++){
        if(i<l-1){
            left.push_back(v[i]);
        }else if(i>r-1){
            right.push_back(v[i]);
        }else{
            mid.push_back(v[i]);
        }
    }
    sort(left.begin(), left.end());
    sort(right.begin(), right.end());
    sort(mid.begin(), mid.end());
    int mergeWithLeft = 0 ;
    int mergeWithRight = 0;
    int L_idx = 0 ; 
    int R_idx = 0;
    for (int i = mid.size()-1; i>= 0 ; i--){
        if(R_idx<right.size()){
            mergeWithRight +=  min(mid[i],right[R_idx]);
            R_idx++;
        }else{
            mergeWithRight += mid[i];
        }
        if(L_idx<left.size()){
            mergeWithLeft +=  min(mid[i],left[L_idx]);
            L_idx++;
        }else{
            mergeWithLeft += mid[i];
        }
    }
    cout << min(mergeWithLeft, mergeWithRight) << "\n";
}

int main()
{
    FAST_IO;

    int t; // Number of test cases
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}


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

using namespace std;



// Fast I/O

#define FAST_IO                       \

    ios_base::sync_with_stdio(false); \

    cin.tie(nullptr);                 \

    cout.tie(nullptr);



// Aliases for convenience

using ll = long long;

using vi = vector<int>;

using vll = vector<long long>;

using pii = pair<int, int>;



// Constants

const int MOD = 1e9 + 7;

const int INF = INT_MAX;



// Solve function

void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> v(n);

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

        cin >> v[i];

    }

    vector<int> left;

    vector<int> right;

    vector<int> mid;

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

        if(i<l-1){

            left.push_back(v[i]);

        }else if(i>r-1){

            right.push_back(v[i]);

        }else{

            mid.push_back(v[i]);

        }

    }

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

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

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

    ll mergeWithLeft = 0 ;

    ll mergeWithRight = 0;

    int L_idx = 0 ; 

    int R_idx = 0;

    for (int i = mid.size()-1; i>= 0 ; i--){

        if(R_idx<right.size()){

            mergeWithRight +=  min(mid[i],right[R_idx]);

            R_idx++;

        }else{

            mergeWithRight += mid[i];

        }

        if(L_idx<left.size()){

            mergeWithLeft +=  min(mid[i],left[L_idx]);

            L_idx++;

        }else{

            mergeWithLeft += mid[i];

        }

    }

    cout << min(mergeWithLeft, mergeWithRight) << "\n";

}



int main()

{

    FAST_IO;



    int t; // Number of test cases

    cin >> t;

    while (t--)

    {

        solve();

    }



    return 0;

}