Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

#include <vector>

#include <algorithm>

#include <numeric>



using ll = long long;

using namespace std;



int main() {

    int t;



    cin >> t;

    

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

        ll n, l, r;



        cin >> n;

        cin >> l;

        cin >> r;

        

        vector<ll> preSegment;

        vector<ll> segment;

        vector<ll> postSegment;

        

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

            ll v;

            cin >> v;

            

            if(i<l-1) {

                preSegment.push_back(v);

            } else if (i<r) {

                segment.push_back(v);

            } else {

                postSegment.push_back(v);

            }

            //preSegment.push_back(v);

            //segment.push_back(v);

            //postSegment.push_back(v);

        }



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

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

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





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



        ll Presum = sum;

        ll Postsum = sum;



        for(ll i = 0; i < min(r-l+1, l-1); i++) {

            if(preSegment.at(i)<segment.at(r-l-i)) {

                Presum += preSegment.at(i);

                Presum -= segment.at(r-l-i);

            };

        }



        for(ll i = 0; i < min(r-l+1, n-r); i++) {

            if(postSegment.at(i)<segment.at(r-l-i)) {

                Postsum += postSegment.at(i);

                Postsum -= segment.at(r-l-i);

            };

        }





        printf("%d\n", min(min(sum, Postsum), Presum));

        //printf("%d\n", sum);

        

    }



}

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

#include <vector>

#include <algorithm>

#include <numeric>



using ll = long long;

using namespace std;



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    

    int t;



    cin >> t;

    

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

        ll n, l, r;



        cin >> n;

        cin >> l;

        cin >> r;

        

        vector<ll> preSegment;

        vector<ll> segment;

        vector<ll> postSegment;

        

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

            ll v;

            cin >> v;

            

            if(i<l-1) {

                preSegment.push_back(v);

            } else if (i<r) {

                //segment.push_back(v);



                preSegment.push_back(v);

                postSegment.push_back(v);



            } else {

                postSegment.push_back(v);

            }

            //preSegment.push_back(v);

            //segment.push_back(v);

            //postSegment.push_back(v);

        }



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

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

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





        ll Presum = accumulate(preSegment.begin(), preSegment.begin() + r - l + 1, 0);



        ll Postsum = accumulate(postSegment.begin(), postSegment.begin() + r - l + 1, 0);

/*

        for(ll i = 0; i < min(r-l+1, l-1); i++) {

            if(preSegment[i]<segment[r-l-i]) {

                Presum += preSegment[i];

                Presum -= segment.at(r-l-i);

            } else break;

        }



        for(ll i = 0; i < min(r-l+1, n-r); i++) {

            if(postSegment.at(i)<segment.at(r-l-i)) {

                Postsum += postSegment.at(i);

                Postsum -= segment.at(r-l-i);

            } else break;

        }

*/



        cout << min( Postsum, Presum) << "\n";

        //printf("%d\n", sum);

        

    }



}