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

Previous submission (verdict: Wrong answer on test 2):
    #include <bits/stdc++.h>

    #include<unistd.h>

    #include<thread>

    using namespace std;

    #define ld double

    #define ll long long

    #define pb emplace_back

    #define mk make_pair

    #define mod 1000000007

    #define ff first

    #define ss second

    #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #define all(x) x.begin(),x.end()

    #define sz(v) (int)v.size()

    #define int long long

    const int mxn =1e6+5;

    int X[]={1,-1,0,0};

    int Y[]={0,0,1,-1};

    char dir[]={'D','U','R','L'};

     

     

    ll gcd(ll a,ll b){

            while(b){

                a%=b;

                swap(a,b);

            }

            return a;

    }

        // _________________________________________Sieve________________________________________

    vector<int> prime;

    void sieve(){

            int vis[mxn];

            memset(vis,0,sizeof(vis));

            for(int i=2;i<mxn;i++){

                if(vis[i]==0)

                    prime.push_back(i);

                for(int j=i;j<mxn;j+=i){

                    if(vis[j]==0){

                        vis[j]=1;

                    }

                }

            }

    }

        // _________________________________________Power_________________________________________

    ll power(ll a,ll b){

            ll ans =1;

            while(b>0){

                if(b&1)ans = ans*a;

                a = a*a;

                b>>=1;

            }

            return ans;

    }

     

    // -------------------------------------------Code--------------------------------------------- 

    

    void solve(){

      int n,l,r;

      cin>>n>>l>>r;

      vector<int>ar(n);

      for( int &i :ar){

        cin>>i;

      }

      sort(ar.begin(),ar.begin()+l);

      sort(ar.begin()+l,ar.begin()+r);

      sort(ar.begin()+r,ar.end());

      int k=0;

      int sum=0;

      int ans =0;

      for(int i=r-1;i>=l-1;i--){

        if(k<l-1 && ar[k]<=ar[i]){

          sum+=ar[k];

          k++;

        }

        else{

          sum+=ar[i];

        }

      }

      ans = sum;

      k = r;

      sum=0;

      

      for(int i=r-1;i>=l-1;i--){

        if(k<n &&ar[k]<=ar[i]){

          

          sum+=ar[k];

          k++;

        }

        else{

          sum+=ar[i];

        }

      }

      ans = min(ans,sum);

      cout<<ans<<"\n";

      

    }      

     

     

    int32_t main(){ 

            FIO

            int t;

            cin>>t;

            

            // t = 1;

            while(t--){

                // tt++;

                solve();

                // cout<<"Case #"<<tt<<" ";

            }

    }           













Submission (verdict: Accepted):
    #include <bits/stdc++.h>
    #include<unistd.h>
    #include<thread>
    using namespace std;
    #define ld double
    #define ll long long
    #define pb emplace_back
    #define mk make_pair
    #define mod 1000000007
    #define ff first
    #define ss second
    #define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define all(x) x.begin(),x.end()
    #define sz(v) (int)v.size()
    #define int long long
    const int mxn =1e6+5;
    int X[]={1,-1,0,0};
    int Y[]={0,0,1,-1};
    char dir[]={'D','U','R','L'};
     
     
    ll gcd(ll a,ll b){
            while(b){
                a%=b;
                swap(a,b);
            }
            return a;
    }
        // _________________________________________Sieve________________________________________
    vector<int> prime;
    void sieve(){
            int vis[mxn];
            memset(vis,0,sizeof(vis));
            for(int i=2;i<mxn;i++){
                if(vis[i]==0)
                    prime.push_back(i);
                for(int j=i;j<mxn;j+=i){
                    if(vis[j]==0){
                        vis[j]=1;
                    }
                }
            }
    }
        // _________________________________________Power_________________________________________
    ll power(ll a,ll b){
            ll ans =1;
            while(b>0){
                if(b&1)ans = ans*a;
                a = a*a;
                b>>=1;
            }
            return ans;
    }
     
    // -------------------------------------------Code--------------------------------------------- 
    
    void solve(){
      int n,l,r;
      cin>>n>>l>>r;
      vector<int>ar(n);
      for( int &i :ar){
        cin>>i;
      }
      vector<int>b;
      b = ar;
      sort(ar.begin(),ar.begin()+r,greater<int>());
      sort(b.begin()+l-1,b.end());
      
      int s1=0;
      int s2=0;
      for(int i=l-1;i<r;i++){
        s1+=ar[i];
        s2+=b[i];
      }
      cout<<min(s1,s2)<<"\n";
    }      
     
     
    int32_t main(){ 
            FIO
            int t;
            cin>>t;
            
            // t = 1;
            while(t--){
                // tt++;
                solve();
                // cout<<"Case #"<<tt<<" ";
            }
    }