Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace std;

using namespace __gnu_pbds;



#define ff first

#define ss second

#define int long long

#define pb push_back

#define mp make_pair

#define pii pair<int, int>

#define vi vector<int>

#define mii map<int, int>

#define pqb priority_queue<int>

#define pqs priority_queue<int, vi, greater<int>>

#define setbits(x) __builtin_popcountll(x)

#define zrobits(x) __builtin_ctzll(x)

#define mod 100000007

#define inf 1e18

#define ps(x, y) fixed << setprecision(y) << x

#define mk(arr, n, type) type *arr = new type[n]

#define w(x)  \

    int x;    \

    cin >> x; \

    while (x--)



mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;



void c_p_c()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif

}



int32_t main()

{

    c_p_c();

    w(x)

    {

        int n;

        int l;

        int r;

        cin >> n >> l >> r;

        vi arr(n);

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

            cin >> arr[i];

        vi left_seg;

        vi right_seg;

        vi seg;

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

        {

            seg.pb(arr[i]);

        }

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

        {

            left_seg.pb(arr[i]);

        }

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

        {

            right_seg.pb(arr[i]);

        }



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

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

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

        vi temp = seg;

        int left = 0;

        int s = seg.size() - 1;

        while (s >= 0 && left < left_seg.size() && left_seg[left] < seg[s])

        {

            seg[s] = left_seg[left];

            s--;

            left++;

        }

        int answer_left = accumulate(seg.begin(), seg.end(), 0LL);

        

        int right = 0;

        s = temp.size() - 1;

        while (s >= 0 && right < right_seg.size() && right_seg[right] < temp[s])

        {

            temp[s] = right_seg[right];

            s--;

            right++;

        }

        int answer_right = accumulate(temp.begin(), temp.end(), 0LL);

        int final_answer = min(answer_left, answer_right);

        

        cout << final_answer << endl;

    }

    return 0;

}



Solution 2 (runtime: 155 ms):
#include <iostream>

#include<map>

#include<vector>

#include <set>

#include <algorithm>

#include<string>

#include<queue>

#include<stack>

#include <iomanip>//设置输出精度

#include<list>

#include<cmath>

#include<deque>

#define int long long

#define float  double

using namespace std;

#define PI pair<int,int>

#define PII pair<char,char>

const int N= 1e6;

int a[N],b[N],c[N];

int quickpow(int a, int b) {

	int sum = 1;

	while (b) {

		if (b & 1)

			sum *= a;

		b >>= 1;

		a *= a;

	}

	return sum;

}

int gcd(int x, int y)

{

	int r;

	while (x % y != 0) {

		r = x % y;

		x = y;

		y = r;

	}

	return y;

}



void solve() {

	int n, r, l;

	cin >> n >> l >> r;

	multiset<int>mp1;

	multiset<int>mp2;

	multiset<int>::iterator it;

	int a;

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

		cin >> a;

		if (i >= 1 && i <= r)

			mp1.insert(a);

		if (i >= l && i <= n)

			mp2.insert(a);

	}

	int number =r-l + 1;

	int ans1 = 0;

	int ans2 = 0;

	it = mp1.begin();

	for (int i = 0; i < number; i++) {

		ans1 += *it;

		it++;

	}

	it = mp2.begin();

	for (int i = 0; i < number; i++) {

		ans2 += *it;

		it++;

	}

	cout << min(ans1,ans2) << endl;

}

signed main() {

	cin.tie(0)->sync_with_stdio(0);

	cout << fixed << setprecision(8);

	int T;

	cin >> T;

	while (T--)

		solve();

	return 0;

}