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;

#ifndef ONLINE_JUDGE
    #define debug(x) cerr<<#x<<": "<<x<<endl;
#else
    #define debug(x)
    #define cerr if (false) cerr
#endif

#define endl "\n"       //remove this for interactive problems
#define space " "
#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> void printit(vector<T> v, int x=1) {if(x==2) return; for (T i : v) if (x==1) cout<<i<<" "; else cerr<<i<<" "; if (x==1) cout<<endl; else cerr<<endl;}

//---------------------------------------------------------------------------------------------------//

/*
auto check = [&](int mid) -> bool{
        //conditions
        return true;
    };
*/
int MOD = 1e9 + 7;
// (a += (b*c)%MOD ) %= MOD ;

void solve()
{
    int n,l,r;
    cin>>n>>l>>r;
    
    l--;
    r--;

    vector<int> arr(n, 0);
    vector<int> segment, left, right;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if (i<l)
        {
            left.push_back(arr[i]);
        }
        else if (i>=l && i<=r)
        {
            segment.push_back(arr[i]);
        } else
        {
            right.push_back(arr[i]);
        }
    }

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

    int sum = accumulate(segment.begin(), segment.end(), 0);

    int answer = sum;
    int i=0, j=segment.size();
    j--;
    while (j>=0 && i<left.size())
    {
        sum = sum - segment[j];
        sum += left[i];
        j--;
        i++;

        answer = min(answer, sum);
    }
    sum = accumulate(segment.begin(), segment.end(), 0);

    i = 0, j = segment.size();
    j--;
    while (j >= 0 && i < right.size())
    {
        sum = sum - segment[j];
        sum += right[i];
        j--;
        i++;

        answer = min(answer, sum);
    }

    cout<<answer<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;cin >> t;while (t--) 
    solve();

    
    return 0;
}

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

#ifndef ONLINE_JUDGE
    #define debug(x) cerr<<#x<<": "<<x<<endl;
#else
    #define debug(x)
    #define cerr if (false) cerr
#endif

#define endl "\n"       //remove this for interactive problems
#define space " "
#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <class T> void printit(vector<T> v, int x=1) {if(x==2) return; for (T i : v) if (x==1) cout<<i<<" "; else cerr<<i<<" "; if (x==1) cout<<endl; else cerr<<endl;}

//---------------------------------------------------------------------------------------------------//

/*
auto check = [&](int mid) -> bool{
        //conditions
        return true;
    };
*/
int MOD = 1e9 + 7;
// (a += (b*c)%MOD ) %= MOD ;

void solve()
{
    int n,l,r;
    cin>>n>>l>>r;
    
    l--;
    r--;

    vector<int> arr(n, 0);
    vector<int> segment, left, right;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if (i<l)
        {
            left.push_back(arr[i]);
        }
        else if (i>=l && i<=r)
        {
            segment.push_back(arr[i]);
        } else
        {
            right.push_back(arr[i]);
        }
    }

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

    int sum = accumulate(segment.begin(), segment.end(), 0LL);

    int answer = sum;
    
    int i=0, j=segment.size();
    j--;
    while (j>=0 && i<left.size())
    {
        sum = sum - segment[j];
        sum += left[i];
        j--;
        i++;

        answer = min(answer, sum);
    }
    sum = accumulate(segment.begin(), segment.end(), 0LL);

    i = 0, j = segment.size();
    j--;
    while (j >= 0 && i < right.size())
    {
        sum = sum - segment[j];
        sum += right[i];
        j--;
        i++;

        answer = min(answer, sum);
    }

    cout<<answer<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;cin >> t;while (t--) 
    solve();

    
    return 0;
}