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

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

        ll n,l,r;

        cin>>n>>l>>r;

        vector<ll> a(n);

        fi cin>>a[i];

        vector<ll> b(a.begin()+l-1,a.begin()+r);

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

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

        vector<ll> left,right;

        ll ans1=ans,ans2=ans;

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

            left.push_back(a[i]);

        }

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

            right.push_back(a[i]);

        }

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

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

        vector<ll> left1,right1;

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

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

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

        ll 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";

    }   

}

Submission (verdict: Accepted):
#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--){

        ll n,l,r;

        cin>>n>>l>>r;

        vector<ll> a(n);

        fi cin>>a[i];

        vector<ll> b(a.begin()+l-1,a.begin()+r);

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

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

        vector<ll> left,right;

        ll ans1=ans,ans2=ans;

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

            left.push_back(a[i]);

        }

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

            right.push_back(a[i]);

        }

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

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

        vector<ll> left1,right1;

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

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

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

        ll 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";

    }   

}