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

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

using namespace std;

//#include "debug.h"

 

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

typedef pair<int, int> pi;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

 

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_mset;

 

 

 

#define ll long long int

#define ld long double

#define nl cout<<"\n"

#define yes cout<<"Yes\n"

#define no cout<<"No\n"

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

#define rall(a)  a.rbegin(),a.rend()

#define bit_count(x)  __builtin_popcountll(x)

#define msb(x) (63-__builtin_clzll(x))

#define extra_(n) fixed << setprecision(n)

#define two_D_vector(v,n,m,val) vector<vector<ll>>v(n,vector<ll>(m,val));

#define _3D_vector(v,n,m,z,val) vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(m, vector<ll>(z, val)));

#define In_The_Name_of_Allah ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define T cin>>t; while(t--)

#define T1 t=1; while(t--)

//lazy segtree

#define ptr(A) shared_ptr<A>



//sort(a.begin(), a.end(), greater<int>());

const ll mod=998244353;

const ll mod1=1e9+7;

const ll inf=5e18;

const ll minf=-5e18;

const ll N=2e6+5;

const ld eps = 1e-8;









// Mathematical functions

ll gcd(ll a, ll b) {if (b == 0)return a; return gcd(b, a % b);}

ll lcm(ll a, ll b) {return (a / gcd(a, b) * b);}

ll pw(ll x, ll y) { ll a = 1; for (ll i = 0; i < y; i++) a *= x; return a;}

long long square_root(ll x) {

    if(x==0)return 0;

    long long low = 1, high = 3e9, ans = 1; while (low <= high) {

        long long mid = (low + high) / 2;

        if (mid * mid <= x) {ans = mid; low = mid + 1;} else high = mid - 1;

    } return ans;

}

 

bool isPrime(ll n)

{

    if (n <= 1)return false; if (n <= 3)return true; if (n % 2 == 0 || n % 3 == 0)return false;

    for (int i = 5; i * i <= n; i = i + 6)if (n % i == 0 || n % (i + 2) == 0)return false;

    return true;

}

 

bool sortbysec(const pair<int,int> &a,

              const pair<int,int> &b)

{

    return (a.second < b.second);

}

 



 

 

/*set<int>st;

 

bool vis[N];

 

void sieve(){

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

        if(vis[i] == 0){

            st.insert(i);

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

                vis[j] = 1;

            }

        }

    }

 

}*/

 

//vector<vector<ll>>v(N,vector<ll>(1,0));

/*ll spf[N+5];

 

void sieve()

{

    spf[1] = 1;

    for (ll i=2; i<N; i++)

        spf[i] = i;

 

    for (ll i=4; i<N; i+=2)

        spf[i] = 2;

 

    for (ll i=3; i*i<N; i++)

    {

        if (spf[i] == i)

        {

            for (ll j=i*i; j<N; j+=i)

 

                if (spf[j]==j)

                    spf[j] = i;

        }

    }

}

 

set<ll> getFactorization(ll x)

{

    set<ll> ret;

    while (x != 1)

    {

        ret.insert(spf[x]);

        x = x / spf[x];

    }

    return ret;

}*/







void come_on(ll ct){

    ll n,m,k,x,y,i,j,z,x1,y1;

    cin>>n>>x>>y;

    vector<ll>a(n);

    for(i=0;i<n;i++)cin>>a[i];

    if((y-x+1)==n){

        ll sum=0;

        for(i=0;i<n;i++)sum+=a[i];

        cout<<sum;nl;

        return;

    }

    multiset<ll>st;

    ll sum=0;

    for(i=x-1;i<y;i++)st.insert(a[i]);

        

    for(i=0;i<x;i++){

        if(a[i]<(*st.rbegin())){

            ll temp=*st.rbegin();

            st.insert(a[i]);

            st.erase(st.find(temp));

        }

    }

    for(auto it:st)sum+=it;

        st.clear();

    for(i=x-1;i<y;i++)st.insert(a[i]);

    for(i=y;i<n;i++){

        if(a[i]<(*st.rbegin())){

            ll temp=*st.rbegin();

            st.insert(a[i]);

            st.erase(st.find(temp));

        }

    }

    ll sum1=0;

    for(auto it:st)sum1+=it;

    cout<<min(sum,sum1);nl;



    

}

 

 

int main()

{

    In_The_Name_of_Allah;

    //

    

    //

    ll t,ct=1;

    T

    {

       come_on(ct);

       ct++;

 

    }

    return 0;

 

}

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

using namespace std;

//#include "debug.h"

 

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

typedef pair<int, int> pi;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

 

#include <ext/pb_ds/tree_policy.hpp>

#include <ext/pb_ds/assoc_container.hpp>

typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_mset;

 

 

 

#define ll long long int

#define ld long double

#define nl cout<<"\n"

#define yes cout<<"Yes\n"

#define no cout<<"No\n"

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

#define rall(a)  a.rbegin(),a.rend()

#define bit_count(x)  __builtin_popcountll(x)

#define msb(x) (63-__builtin_clzll(x))

#define extra_(n) fixed << setprecision(n)

#define two_D_vector(v,n,m,val) vector<vector<ll>>v(n,vector<ll>(m,val));

#define _3D_vector(v,n,m,z,val) vector<vector<vector<ll>>> dp(n, vector<vector<ll>>(m, vector<ll>(z, val)));

#define In_The_Name_of_Allah ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define T cin>>t; while(t--)

#define T1 t=1; while(t--)

//lazy segtree

#define ptr(A) shared_ptr<A>



//sort(a.begin(), a.end(), greater<int>());

const ll mod=998244353;

const ll mod1=1e9+7;

const ll inf=5e18;

const ll minf=-5e18;

const ll N=2e6+5;

const ld eps = 1e-8;









// Mathematical functions

ll gcd(ll a, ll b) {if (b == 0)return a; return gcd(b, a % b);}

ll lcm(ll a, ll b) {return (a / gcd(a, b) * b);}

ll pw(ll x, ll y) { ll a = 1; for (ll i = 0; i < y; i++) a *= x; return a;}

long long square_root(ll x) {

    if(x==0)return 0;

    long long low = 1, high = 3e9, ans = 1; while (low <= high) {

        long long mid = (low + high) / 2;

        if (mid * mid <= x) {ans = mid; low = mid + 1;} else high = mid - 1;

    } return ans;

}

 

bool isPrime(ll n)

{

    if (n <= 1)return false; if (n <= 3)return true; if (n % 2 == 0 || n % 3 == 0)return false;

    for (int i = 5; i * i <= n; i = i + 6)if (n % i == 0 || n % (i + 2) == 0)return false;

    return true;

}

 

bool sortbysec(const pair<int,int> &a,

              const pair<int,int> &b)

{

    return (a.second < b.second);

}

 



 

 

/*set<int>st;

 

bool vis[N];

 

void sieve(){

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

        if(vis[i] == 0){

            st.insert(i);

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

                vis[j] = 1;

            }

        }

    }

 

}*/

 

//vector<vector<ll>>v(N,vector<ll>(1,0));

/*ll spf[N+5];

 

void sieve()

{

    spf[1] = 1;

    for (ll i=2; i<N; i++)

        spf[i] = i;

 

    for (ll i=4; i<N; i+=2)

        spf[i] = 2;

 

    for (ll i=3; i*i<N; i++)

    {

        if (spf[i] == i)

        {

            for (ll j=i*i; j<N; j+=i)

 

                if (spf[j]==j)

                    spf[j] = i;

        }

    }

}

 

set<ll> getFactorization(ll x)

{

    set<ll> ret;

    while (x != 1)

    {

        ret.insert(spf[x]);

        x = x / spf[x];

    }

    return ret;

}*/







void come_on(ll ct){

    ll n,m,k,x,y,i,j,z,x1,y1;

    cin>>n>>x>>y;

    string s;

    s+=to_string(x);

    s+=',';

    s+=to_string(y);

    s+=',';

    vector<ll>a(n);

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

        cin>>a[i];

        s+=to_string(a[i]);

        s+=',';

    }

    if(ct==84){

        cout<<s;nl;

        return;

    }

    if((y-x+1)==n){

        ll sum=0;

        for(i=0;i<n;i++)sum+=a[i];

        cout<<sum;nl;

        return;

    }

    multiset<ll>st;

    ll sum=0;

    for(i=x-1;i<y;i++)st.insert(a[i]);



    for(i=0;i<x;i++){

        if(a[i]<(*st.rbegin())){

            ll temp=*st.rbegin();

            st.insert(a[i]);

            st.erase(st.find(temp));

        }

    }

    for(auto it:st)sum+=it;

        st.clear();

    for(i=x-1;i<y;i++)st.insert(a[i]);

    for(i=y;i<n;i++){

        if(a[i]<(*st.rbegin())){

            ll temp=*st.rbegin();

            st.insert(a[i]);

            st.erase(st.find(temp));

        }

    }

    ll sum1=0;

    for(auto it:st)sum1+=it;

    cout<<min(sum,sum1);nl;



    

}

 

 

int main()

{

    In_The_Name_of_Allah;

    //

    

    //

    ll t,ct=1;

    T

    {

       come_on(ct);

       ct++;

 

    }

    return 0;

 

}