Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
/* Authour : Shivanshu Garg */ 

#include <bits/stdc++.h>

using namespace std;

 

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

typedef long long ll;

#define endl '\n'

#define pb push_back

#define pii pair<ll, ll>

#define vi vector<ll>

#define vii vector<pii>

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

 

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

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

bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; }

 

const int MOD = 1e9 + 7;

const int INF = 1e18;

const int MAXN = 1e5 + 5;



void solve() {

    ll n, l, r;

    cin>>n>>l>>r;

    

    vi arr(n);

    

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

    l--,r--;

    

    ll sum = 0;

    priority_queue<ll> pq1;

    

    priority_queue<ll , vector<ll> , greater<ll>> pq2;

    

    for(ll i = l; i<=r; i++){

        pq1.push(arr[i]); 

        sum+=arr[i];

    }

    for(ll i = 0; i<l; i++){

        pq2.push(arr[i]); 

    }

    

    for(ll i=r+1; i<n; i++){

        pq2.push(arr[i]);

    }

    

    while(!pq1.empty() && !pq2.empty()){

        if(pq2.top()>pq1.top()){

            break; 

        }

        

        sum-=pq1.top();

        pq1.pop(); 

        sum+=pq2.top();

        pq2.pop();

    }

    

    cout<<sum<<endl; 

}

 

int32_t main() {

    fastio();

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}

Submission (verdict: Accepted):
/* Authour : Shivanshu Garg */ 

#include <bits/stdc++.h>

using namespace std;

 

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

typedef long long ll;

#define endl '\n'

#define pb push_back

#define pii pair<ll, ll>

#define vi vector<ll>

#define vii vector<pii>

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

 

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

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

bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i * i <= n; ++i) if (n % i == 0) return false; return true; }

 

const int MOD = 1e9 + 7;

const int INF = 1e18;

const int MAXN = 1e5 + 5;



void solve() {

    ll n, l, r;

    cin>>n>>l>>r;

    

    vi arr(n);

    

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

    l--,r--;

    

    ll sum = 0;

    priority_queue<ll> pq1,pq4;

    

    priority_queue<ll , vector<ll> , greater<ll>> pq2,pq3;

    

    for(ll i = l; i<=r; i++){

        pq1.push(arr[i]); 

        pq4.push(arr[i]); 

        sum+=arr[i];

    }

    for(ll i = 0; i<l; i++){

        pq2.push(arr[i]); 

    }

    

    for(ll i=r+1; i<n; i++){

        pq3.push(arr[i]);

    }

    ll sum1= sum; 

    while(!pq1.empty() && !pq2.empty()){

        if(pq2.top()>pq1.top()){

            break; 

        }

        

        sum-=pq1.top();

        pq1.pop(); 

        sum+=pq2.top();

        pq2.pop();

    }

    while(!pq4.empty() && !pq3.empty()){

        if(pq3.top()>pq4.top()){

            break; 

        }

        

        sum1-=pq4.top();

        pq4.pop(); 

        sum1+=pq3.top();

        pq3.pop();

    }

    

    

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

}

 

int32_t main() {

    fastio();

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}