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

Previous submission (verdict: Wrong answer on test 8):
#include<iostream>
#define ll long long 
#include<bits/stdc++.h>
#include<vector>

using namespace std;

void rudrakumarsharma(){

    int n , l, r;
    cin >> n >> l >> r;

    vector <int> arr(n);


    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        
    }

    // sort(arr.begin(), arr.end());

    // int win_size = r - l + 1;

    // int sum = 0;

    // for(int i = 0; i < win_size; i++)
    // {
    //     sum += arr[i];
    // }

    // cout << sum << endl;

    if ( l == r)
    {
        int mini = *min_element(arr.begin(), arr.end());
        cout << mini << endl;
        return;
    }

    sort(arr.begin(), arr.begin() + l - 1);
    
    sort(arr.begin() + l - 1 , arr.begin() + r );

    sort(arr.begin() + r, arr.end());

    // for(auto & c: arr)
    // {
    //     cout << c;
    // }
    // cout << endl;

    vector <int> pre;
    vector <int> mid;
    vector <int> suff;

    int sum1 = 0;
    int sum2 = 0;
    int sum3 = 0;

    for (int i = 0 ; i < l-1; i++)
    {
        sum1 += arr[i];

        pre.push_back(sum1); 
    }
    // for(auto & c: pre)
    // {
    //     cout << c << " ";
    // }
    // cout << endl;

    for (int i = r - 1; i >= l-1; i--)
    {
        sum2 += arr[i];

        mid.push_back(sum2); 
    }
    // for(auto & c: mid)
    // {
    //     cout << c << " ";
    // }
    // cout << endl;

    for (int i = r ; i < arr.size(); i++)
    {
        sum3 += arr[i];

        suff.push_back(sum3); 
    }
    // for(auto & c: suff)
    // {
    //     cout << c << " ";
    // }
    // cout << endl;

    int arr_sum = mid[mid.size() - 1];
    // cout << arr_sum << endl;

    int idx1 = min(pre.size(), mid.size());

    int ans = arr_sum;
    // cout << arr_sum << endl;


    for( int i = 0; i < idx1; i++)
    {
        int temp = arr_sum;

        temp -= mid[i];
        temp += pre[i];

        ans = min(ans , temp);
    }

    // cout << ans << endl;

    int idx2 = min(suff.size(), mid.size());

    for( int i = 0; i < idx2; i++)
    {
        int temp = arr_sum;

        temp -= mid[i];
        temp += suff[i];

        ans = min(ans , temp);
    }

    cout << ans << endl;


}

int main(){

    int t;
    cin >> t;

    while(t--){

        rudrakumarsharma();
    }
    return 0;

}


Submission (verdict: Accepted):
#include<iostream>
#define ll long long 
#include<bits/stdc++.h>
#include<vector>

using namespace std;

void rudrakumarsharma(){

    ll n , l, r;
    cin >> n >> l >> r;

    vector <ll> arr(n);


    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        
    }

    // sort(arr.begin(), arr.end());

    // int win_size = r - l + 1;

    // int sum = 0;

    // for(int i = 0; i < win_size; i++)
    // {
    //     sum += arr[i];
    // }

    // cout << sum << endl;

    if ( l == r)
    {
        ll mini = *min_element(arr.begin(), arr.end());
        cout << mini << endl;
        return;
    }

    sort(arr.begin(), arr.begin() + l - 1);
    
    sort(arr.begin() + l - 1 , arr.begin() + r );

    sort(arr.begin() + r, arr.end());


    vector <ll> pre;
    vector <ll> mid;
    vector <ll> suff;

    ll sum1 = 0;
    ll sum2 = 0;
    ll sum3 = 0;

    for (int i = 0 ; i < l-1; i++)
    {
        sum1 += arr[i];

        pre.push_back(sum1); 
    }


    for (int i = r - 1; i >= l-1; i--)
    {
        sum2 += arr[i];

        mid.push_back(sum2); 
    }


    for (int i = r ; i < arr.size(); i++)
    {
        sum3 += arr[i];

        suff.push_back(sum3); 
    }


    ll arr_sum = mid[mid.size() - 1];


    ll idx1 = min(pre.size(), mid.size());

    ll ans = arr_sum;



    for( int i = 0; i < idx1; i++)
    {
        ll temp = arr_sum;

        temp -= mid[i];
        temp += pre[i];

        ans = min(ans , temp);
    }



    ll idx2 = min(suff.size(), mid.size());

    for( int i = 0; i < idx2; i++)
    {
        ll temp = arr_sum;

        temp -= mid[i];
        temp += suff[i];

        ans = min(ans , temp);
    }

    cout << ans << endl;


}

int main(){

    int t;
    cin >> t;

    while(t--){

        rudrakumarsharma();
    }
    return 0;

}