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() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    

    int t;



    cin >> t;

    

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

        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);

        

    }



}

Submission (verdict: Accepted):
#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 ii = 0; ii<t; ii++) {

        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, (ll) 0);



        ll Postsum = accumulate(postSegment.begin(), postSegment.begin() + r - l + 1, (ll) 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);

        

    }



}