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

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#include<unordered_map>	
using namespace std;
#define ll long long int
#define vi vector<ll> 
#define all(v) v.begin() , v.end()
#define srt(v) sort(v.begin(), v.end())
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define co(c) cout<<c<<"\n"
#define rn return 
#define acc(v) accumulate(v.begin() , v.end() , 0)


template<class T, class U> istream& operator>>(istream &is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T> istream& operator>>(istream& is, vector<T>& vec) { for(auto &x : vec) cin >> x; return is; }
template<class T, class U> ostream& operator<<(ostream &os, const pair<T, U>& p) { os << "<" << p.first << "," << p.second << ">"; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for(auto x : vec) os << x << " "; return os; }

void solve(){
    int n ; 
     cin >> n ; 
     int a, b; 
     cin >> a >> b;
     vi arr(n, 0 );
     cin >> arr;
     
     sort(arr.begin() , arr.begin() + a);
     sort(arr.begin() + a , arr.begin() + b);
     sort(arr.begin() + b , arr.end());

     int cnt = b - a  +1;
     a--;
     b--;
     int curr = 0;
     int i = 0; 
     int j = a;
     int first = 0;
     

     while(curr < cnt){
        
         if( i < a && (arr[i] < arr[j]  || j > b)){
            first += arr[i];
            i++;
         }
         else if( j <= b && (arr[j] <= arr[i] || i >= a)){
            first += arr[j];
            j++;
        }

        curr++;
     }

     int last = first ;
     i = b+1;
     first = 0;
     //a = n;
     curr = 0;
     j = a;

     while(curr < cnt){
           
         if(i < n && ( arr[i] < arr[j] || j> b)){
            first += arr[i++];      
         } 
         else if( j <= b && (arr[j] <= arr[i] || i>=n)){
            first += arr[j++];
         } 
            curr++;
     } 
   

     co(min(last,first));


     
  
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int testcases;
    cin >> testcases;

    //testcases = 1;
    while (testcases--) {
       solve();
    }
    
    return 0;
}




Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#include<unordered_map>	
using namespace std;
#define ll long long int
#define vi vector<ll> 
#define all(v) v.begin() , v.end()
#define srt(v) sort(v.begin(), v.end())
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define co(c) cout<<c<<"\n"
#define rn return 
#define acc(v) accumulate(v.begin() , v.end() , 0)


template<class T, class U> istream& operator>>(istream &is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T> istream& operator>>(istream& is, vector<T>& vec) { for(auto &x : vec) cin >> x; return is; }
template<class T, class U> ostream& operator<<(ostream &os, const pair<T, U>& p) { os << "<" << p.first << "," << p.second << ">"; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for(auto x : vec) os << x << " "; return os; }

void solve(){
    int n ; 
     cin >> n ; 
     int a, b; 
     cin >> a >> b;
     vi arr(n, 0 );
     cin >> arr;
     
     sort(arr.begin() , arr.begin() + a);
     sort(arr.begin() + a , arr.begin() + b);
     sort(arr.begin() + b , arr.end());

     int cnt = b - a  +1;
     a--;
     b--;
     int curr = 0;
     int i = 0; 
     int j = a;
     int first = 0;
     

     while(curr < cnt){
        
         if( i < a && (j > b || arr[i] < arr[j]  )){
            first += arr[i];
            i++;
         }
         else if( j <= b && ( i >= a || arr[j] <= arr[i] )){
            first += arr[j];
            j++;
        }

        curr++;
     }

     int last = first ;
     i = b+1;
     first = 0;
     //a = n;
     curr = 0;
     j = a;

     while(curr < cnt){
           
         if(i < n && ( j > b ||  arr[i] < arr[j] )){
            first += arr[i++];      
         } 
         else if( j <= b && ( i >= n || arr[j] <= arr[i])){
            first += arr[j++];
         } 
            curr++;
     } 
   

     co(min(last,first));


     
  
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int testcases;
    cin >> testcases;

    //testcases = 1;
    while (testcases--) {
       solve();
    }
    
    return 0;
}