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

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

using namespace std;



int main() {

    int t;

    cin >> t;



    while (t--) 

    {

     

     int n,l,r;

     cin>>n>>l>>r;

     vector<int>arr;

     for(int i=0;i<n;i++)

     {

      int x;

      cin>>x;

      arr.push_back(x);

     }



     vector<int>left;

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

     {

      left.push_back(arr[i]);

     }

     vector<int>right;

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

     {

      right.push_back(arr[i]);

     }

     vector<int>v;

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

     {

      v.push_back(arr[i]);

     }



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

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

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



     int sum=accumulate(v.begin(),v.end(),0);

     int lsum=sum;

     int j=0;

     for(int i=v.size()-1;i>=0;i--)

     {

         if(j==left.size())

         break;

           if(left[j]<v[i])

           {

              lsum=lsum-v[i]+left[j];

              

           }

           j++;

     }

     int rsum=sum;

     j=0;

     for(int i=v.size()-1;i>=0;i--)

     {

         if(j==right.size())

         break;

         //cout<<right[j]<<" "<<v[i]<<endl;

           if(right[j]<v[i])

           {

              rsum=rsum-v[i]+right[j];

              

           }

        // cout<<rsum<<endl;

           j++;

     }

    /* for(int i:left)

     cout<<i<<" ";

     cout<<endl;

     for(int i:right)

     cout<<i<<" ";

     cout<<endl;

     cout<<lsum<<" "<<rsum<<endl;*/



     cout<<min(rsum,lsum)<<endl;









    

     }



    

}



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

using namespace std;



int main() {

    int t;

    cin >> t;



    while (t--) 

    {

     

     int n,l,r;

     cin>>n>>l>>r;

     vector<int>arr;

     for(int i=0;i<n;i++)

     {

      int x;

      cin>>x;

      arr.push_back(x);

     }



     vector<int>left;

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

     {

      left.push_back(arr[i]);

     }

     vector<int>right;

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

     {

      right.push_back(arr[i]);

     }

     vector<int>v;

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

     {

      v.push_back(arr[i]);

     }



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

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

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



     long long int sum=accumulate(v.begin(),v.end(),0);

     long long  int lsum=sum;

     int j=0;

     for(int i=v.size()-1;i>=0;i--)

     {

         if(j==left.size())

         break;

           if(left[j]<v[i])

           {

              lsum=lsum-v[i]+left[j];

              

           }

           j++;

     }

     long long int rsum=sum;

     j=0;

     for(int i=v.size()-1;i>=0;i--)

     {

         if(j==right.size())

         break;

         //cout<<right[j]<<" "<<v[i]<<endl;

           if(right[j]<v[i])

           {

              rsum=rsum-v[i]+right[j];

              

           }

        // cout<<rsum<<endl;

           j++;

     }

    /* for(int i:left)

     cout<<i<<" ";

     cout<<endl;

     for(int i:right)

     cout<<i<<" ";

     cout<<endl;

     cout<<lsum<<" "<<rsum<<endl;*/



     cout<<min(rsum,lsum)<<endl;









    

     }



    

}