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

Previous submission (verdict: Wrong answer on test 2):
#pragma GCC optimize("Ofast")

 

#include <bits/stdc++.h>

#ifndef ONLINE_JUDGE

#include "TemplateDebugging.cpp"

#else

#define debug(...)

#define debugArr(...)

#endif

 

using namespace std;

 

#define int long long

#define ull unsigned long long

#define ios ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);

#define F first

#define S second

#define pb push_back

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

#define maxelement(x) *max_element(all(x))

#define minelement(x) *min_element(all(x))

#define lb lower_bound

#define ub upper_bound

 

const int MAXN = 3e5 + 5;

const int MODO = 998244353;

const int MODI = 1234567891;

const int MOD = 1e9 + 7;

const int INF = 1e18;

 

int dx[8] = {-1,0,1,0,0,-1,-1,-1};

int dy[8] = {0,1,0,-1,-1,-1,0,1};

 

// Think greedily



signed main(){

    ios;

    

    int t;

    cin >> t;

    while(t--){

        // 5 2 5

        // 3 3 2 3 5

        // 11



        // 5 2 5

        // 3 3 2 3 5

        

        // minimos de una parte < l, minimos de otra parte > r





        int n, l, r;

        cin >> n >> l >> r;

        l--, r--;

        vector<int> a(n);

        for(auto &i : a) cin >> i;





        priority_queue<int> pq;

        priority_queue<int, vector<int>, greater<int>> left, right;



        for(int i = 0; i < l; i++) left.push(a[i]);

        for(int i = l; i <= r; i++) pq.push(a[i]);

        for(int i = r + 1; i < n; i++) right.push(a[i]);



        int final = 0;

        int x, y;

        x = y = 0;

        int times = r - l + 1;



        while(times-- && !pq.empty()){

            int p = pq.top();

            int k = 1e18, j = 1e18;

            if(!left.empty()) k = left.top();

            if(!right.empty()) j = right.top();

            

            if(k < p){

                final += k;

                left.pop();

            }

            else if(j < p){

                final += j;

                right.pop();

            }

            else{

                final += p;

            }

            

            pq.pop();

        }



        cout << final << endl;

     

    }

}

Submission (verdict: Accepted):
#pragma GCC optimize("Ofast")

 

#include <bits/stdc++.h>

#ifndef ONLINE_JUDGE

#include "TemplateDebugging.cpp"

#else

#define debug(...)

#define debugArr(...)

#endif

 

using namespace std;

 

#define int long long

#define ull unsigned long long

#define ios ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0);

#define F first

#define S second

#define pb push_back

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

#define maxelement(x) *max_element(all(x))

#define minelement(x) *min_element(all(x))

#define lb lower_bound

#define ub upper_bound

 

const int MAXN = 3e5 + 5;

const int MODO = 998244353;

const int MODI = 1234567891;

const int MOD = 1e9 + 7;

const int INF = 1e18;

 

int dx[8] = {-1,0,1,0,0,-1,-1,-1};

int dy[8] = {0,1,0,-1,-1,-1,0,1};

 

// Think greedily



signed main(){

    ios;

    

    int t;

    cin >> t;

    while(t--){

        // 5 2 5

        // 3 3 2 3 5

        // 11



        // 5 2 5

        // 3 3 2 3 5

        

        // minimos de una parte < l, minimos de otra parte > r





        int n, l, r;

        cin >> n >> l >> r;

        l--, r--;

        vector<int> a(n);

        for(auto &i : a) cin >> i;

        

        vector<int> left, right;



        for(int i = 0; i <= r; i++) left.pb(a[i]);

        for(int i = l; i < n; i++) right.pb(a[i]);



        sort(all(left)), sort(all(right));



        int x, y;

        x = y = 0;



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

            x += left[i];

            y += right[i];

        }



        cout << min(x, y) << endl;

     

    }

}