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

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define fi for(int i=0;i<n;i++)
#define fit(a) for(auto it:a)
#define pb push_back
#define pf push_front
#define mi map<int,int>
#define umi unordered_map<int,int>
#define usi unordered_set<int>
#define maxheapint priority_queue<int>
#define maxheappair priority_queue<pair<int,int>>
#define minheapint priority_queue<int,vector<int>,greater<int>>
#define minheappair priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
using namespace std;
void print(vector<int> &a){
    for(auto i:a) cout<<i<<" ";
    cout<<"\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        vi a(n);
        fi cin>>a[i];
        vi b(a.begin()+l-1,a.begin()+r);
        int ans=accumulate(b.begin(),b.end(),0);
        sort(b.begin(),b.end(),greater<int>());
        vi left,right;
        int ans1=ans,ans2=ans;
        for(int i=0;i<l-1;i++){
            left.push_back(a[i]);
        }
        for(int i=r;i<n;i++){
            right.push_back(a[i]);
        }
        sort(left.begin(),left.end());
        sort(right.begin(),right.end());
        vi left1,right1;
        int szl=left.size(),szr=right.size();
        for(int i=0;i<min(szl,r-l+1);i++) left1.push_back(left[i]);
        for(int i=0;i<min(szr,r-l+1);i++) right1.push_back(right[i]);
        int z=0,s=0;
        while(z<left1.size() && s<b.size() && left1[z]<b[s]){
            ans1+=left1[z++];
            ans1-=b[s++];
        }
        z=0,s=0;
        while(z<right1.size() && s<b.size() && right1[z]<b[s]){
            ans2+=right1[z++];
            ans2-=b[s++];
        }
        // cout<<"ARRAY: ";
        // print(a);
        // cout<<"ARRAY B: ";
        // print(b);
        // cout<<"LEFT : ";
        // print(left);
        // cout<<"RIGHT: ";
        // print(right);
        // cout<<"ans1 and 2: ";
        // cout<<ans1<<" "<<ans2<<"\n";
        // cout<<"FINAL\n";
        cout<<min(ans1,ans2)<<"\n";
        cout<<"END\n";
    }   
}

Submission (verdict: Wrong answer on test 8):
#include<bits/stdc++.h>

#define ll long long

#define vi vector<int>

#define vvi vector<vector<int>>

#define vc vector<char>

#define fi for(int i=0;i<n;i++)

#define fit(a) for(auto it:a)

#define pb push_back

#define pf push_front

#define mi map<int,int>

#define umi unordered_map<int,int>

#define usi unordered_set<int>

#define maxheapint priority_queue<int>

#define maxheappair priority_queue<pair<int,int>>

#define minheapint priority_queue<int,vector<int>,greater<int>>

#define minheappair priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>

using namespace std;

void print(vector<int> &a){

    for(auto i:a) cout<<i<<" ";

    cout<<"\n";

}

int main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

    ll t;

    cin>>t;

    while(t--){

        int n,l,r;

        cin>>n>>l>>r;

        vi a(n);

        fi cin>>a[i];

        vi b(a.begin()+l-1,a.begin()+r);

        int ans=accumulate(b.begin(),b.end(),0);

        sort(b.begin(),b.end(),greater<int>());

        vi left,right;

        int ans1=ans,ans2=ans;

        for(int i=0;i<l-1;i++){

            left.push_back(a[i]);

        }

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

            right.push_back(a[i]);

        }

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

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

        vi left1,right1;

        int szl=left.size(),szr=right.size();

        for(int i=0;i<min(szl,r-l+1);i++) left1.push_back(left[i]);

        for(int i=0;i<min(szr,r-l+1);i++) right1.push_back(right[i]);

        int z=0,s=0;

        while(z<left1.size() && s<b.size() && left1[z]<b[s]){

            ans1+=left1[z++];

            ans1-=b[s++];

        }

        z=0,s=0;

        while(z<right1.size() && s<b.size() && right1[z]<b[s]){

            ans2+=right1[z++];

            ans2-=b[s++];

        }

        cout<<min(ans1,ans2)<<"\n";

    }   

}