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

Previous submission (verdict: Wrong answer on test 8):
#include<iostream>

#include<bits/stdc++.h>



using namespace std;



int main()

{

    int t;

    cin>>t;

    vector<int>ans;



    while(t--)

    {

        int n, l, r;

        cin>>n>>l>>r;

        vector<int>arr(n+1);

        vector<int>l1;

        vector<int>l2;

        vector<int>l3;



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

        {

            int a;

            cin>>a;

            arr[i] = a;

        }

        // for(int i=1; i<=n; i++)

        // cout<<arr[i];

        // cout<<endl;



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

        l1.push_back(arr[i]);



        int sum=0;

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

        {

            l2.push_back(arr[i]);

            sum+=arr[i];

        }

        int sum2 = sum;



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

        l3.push_back(arr[i]);



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

        // cout<<l1.size();

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

        // cout<<l2.size();

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

    // cout<<l3.size()<<endl;

    

        int a=0, b=l2.size()-1;

        if(l1.size()>0)

        {

            while(l1[a]<l2[b] && a<l1.size() && b>=0)

            {

                sum+=l1[a];

                sum-=l2[b];

                 a++;

                b--;

            }

        }



        a=0, b=l2.size()-1;

        

        if(l3.size()>0)

        {

            while(l3[a]<l2[b] && a<l3.size() && b>=0)

            {

                // cout<<a<<b<<endl;

                sum2+=l3[a];

                sum2-=l2[b];

             a++;

                b--;

            }

        }



        ans.push_back(min(sum, sum2));

    }

    for(int i=0; i<ans.size(); i++)

    cout<<ans[i]<<endl;



    return 0;

}



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

using namespace std;

int main()
{
    int t;
    cin>>t;
    vector<int>ans;

    while(t--)
    {
        int n, l, r;
        cin>>n>>l>>r;
        vector<int>arr(n+1);
        vector<int>l1;
        vector<int>l2;
        vector<int>l3;

        for(int i=1; i<=n; i++)
        {
            int a;
            cin>>a;
            arr[i] = a;
        }
        // for(int i=1; i<=n; i++)
        // cout<<arr[i];
        // cout<<endl;

        for(int i=1; i<l; i++)
        l1.push_back(arr[i]);

        long long sum=0;
        for(int i=l; i<=r; i++)
        {
            l2.push_back(arr[i]);
            sum+=arr[i];
        }
        long long sum2 = sum;

        for(int i=r+1; i<=n; i++)
        l3.push_back(arr[i]);

        sort(l1.begin(), l1.end());
        // cout<<l1.size();
        sort(l2.begin(), l2.end());
        // cout<<l2.size();
        sort(l3.begin(), l3.end());
    // cout<<l3.size()<<endl;
    
        int a=0, b=l2.size()-1;
        if(l1.size()>0)
        {
            while(l1[a]<l2[b] && a<l1.size() && b>=0)
            {
                sum+=l1[a];
                sum-=l2[b];
                 a++;
                b--;
            }
        }

        a=0, b=l2.size()-1;
        
        if(l3.size()>0)
        {
            while(l3[a]<l2[b] && a<l3.size() && b>=0)
            {
                // cout<<a<<b<<endl;
                sum2+=l3[a];
                sum2-=l2[b];
             a++;
                b--;
            }
        }

        ans.push_back(min(sum, sum2));
    }
    for(int i=0; i<ans.size(); i++)
    cout<<ans[i]<<endl;

    return 0;
}