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

Solution 1 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;

void solve(){
    ll n, l, r;
    cin >> n >> l >> r;

    vector<ll> arr(n+1);
    for (int i = 1; i <= n; i++)
    cin >> arr[i];

    vector<ll> A, B, C;
    for (int i = 1; i < l; i++)
    A.push_back(arr[i]);

    ll tot = 0;
    for (int i = l; i <= r; i++){
        B.push_back(arr[i]);
        tot += arr[i];
    }

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

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    int i = B.size() - 1;
    ll cur = tot, ans =  tot;
    for (int num: A){
        if(num > B[i] || i < 0) break;
        cur -= B[i];
        cur += num;
        i--;
    }
    ans = min(ans, cur);

    i = B.size()-1;
    cur = tot;
    for (int num: C){
        if (num > B[i] || i < 0) break;
        cur -= B[i];
        cur += num;
        i--;
    }
    ans = min(ans, cur);
    cout << ans << "\n";
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    // freopen("sample.in", "r", stdin);

    int t;
    cin >> t;

    while(t--)
    solve();
    return 0;
}

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

using namespace std;



#define F(i, n) for (int i = 0; i < n; i++)

#define vi vector<int>

#define ln long long int

#define test int t; cin >> t; while (t--)

#define ll long long



#ifndef ONLINE_JUDGE

#define debug(x) cerr << #x << " -> "; _print(x); cerr << endl

#else

#define debug(x)

#endif



void _print(int a) { cerr << a << " "; }

void _print(long long a) { cerr << a << " "; }

void _print(char a) { cerr << a << " "; }

void _print(string a) { cerr << a << " "; }

void _print(bool a) { cerr << a << " "; }

template <class T, class V> void _print(pair<T, V> p) { cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}"; }

template <class T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T> void _print(set<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T> void _print(multiset<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T, class V> void _print(map<T, V> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T> void _print(pair<T, T> p) { cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}"; }

template <class T, class V> void _print(multimap<T, V> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T> void _print(unordered_set<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T> void _print(unordered_multiset<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; }

template <class T, class V> void _print(unordered_map<T, V> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]"; }



void solve(){

  int n,l,r; cin >> n >> l >> r;

  vector<int>v(n);

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



  l--,r--;

  vector<int>left;

  vector<int>right;

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

    left.push_back(v[i]);

  }

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

    right.push_back(v[i]);

  }



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

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



  // int sum1 = accumulate(left.begin(),left.begin()+ (int)(r-l+1),0LL);

  // int sum2 = accumulate(right.begin(),right.begin()+ (int)(r-l+1),0LL);

  ll sum1 = 0;

  ll sum2 = 0;



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

    sum1+=left[i];

  }

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

    sum2+=right[i];

  }

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



}

int main() {

#ifndef ONLINE_JUDGE

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

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

    freopen("Error.txt", "w", stderr);

#endif



test{

   solve();

}



    return 0;

}