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

Solution 1 (runtime: 77 ms):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define ff first
#define sc second
#define pb push_back
#define pp pair<int, int>
#define ll long long
#define ull unsigned long long

using namespace std;

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

    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    vector<int> brr = arr;
    sort(brr.begin() + l, brr.end());

    vector<int> crr = arr;
    sort(crr.begin(), crr.begin() + r + 1, greater<int>());

    long long sum_brr = accumulate(brr.begin() + l, brr.begin() + r + 1, 0LL);
    long long sum_crr = accumulate(crr.begin() + l, crr.begin() + r + 1, 0LL);

    cout << min(sum_brr, sum_crr) << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    
    while (t--) {
        solve();
    }

    return 0;
}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
#include <numeric>
using namespace std;

#define fastio()                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

#define pb push_back
#define f(i, s, e) for (long long int i = s; i < e; i++)
#define cf(i, s, e) for (long long int i = s; i <= e; i++)
#define rf(i, e, s) for (long long int i = e - 1; i >= s; i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795

#ifndef ONLINE_JUDGE
#define debug(x)                                                               \
  cerr << #x << " ";                                                           \
  _print(x);                                                                   \
  cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(lld t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(ull t) { cerr << t; }

template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T> void _print(multiset<T> v);
template <class T, class V> void _print(pair<T, V> p) {
  cerr << "{";
  _print(p.ff);
  cerr << ",";
  _print(p.ss);
  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 << "]";
}

ll left_recur(vector<vector<char>> &arr, ll i, ll j, ll prevI, ll prevJ) {

  ll left, up, down;
  left = up = down = 0;
  debug(i) debug(j)
      debug(arr[i][j]) if (j + 1 < arr[0].size() and arr[i][j + 1] == 'B') {
    left = 1 + left_recur(arr, i, j + 1, i, j);
  }
  if (i - 1 >= 0 and arr[i - 1][j] == 'B' and i - 1 != prevI) {
    up = 1 + left_recur(arr, i - 1, j, i, j);
  }
  if (i + 1 < 2 and arr[i + 1][j] == 'B' and i + 1 != prevI) {
    down = 1 + left_recur(arr, i + 1, j, i, j);
  }
  ll temp = max(left, max(up, down));
  debug(temp) return max(left, max(up, down));
}
ll brute_recur(vector<vector<char>> &arr, ll i, ll j, ll prevI, ll prevJ) {

  ll left, up, down;
  left = up = down = 0;
  // if()
  debug(i) debug(j) debug(arr[i][j]) if (j - 1 >= 0 and arr[i][j - 1] == 'B') {
    left = 1 + brute_recur(arr, i, j - 1, i, j);
  }
  if (i - 1 >= 0 and arr[i - 1][j] == 'B' and i - 1 != prevI) {
    up = 1 + brute_recur(arr, i - 1, j, i, j);
  }
  if (i + 1 < 2 and arr[i + 1][j] == 'B' and i + 1 != prevI) {
    down = 1 + brute_recur(arr, i + 1, j, i, j);
  }
  ll temp = max(left, max(up, down));
  debug(temp) return temp;
}
int main() {
  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);
  freopen("error.txt", "w", stderr);
#endif
  int t = 1;
  cin >> t;
  while (t--) {
    ll n, l, r;
    cin >> n >> l >> r;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<ll> s;
    vector<ll> left;
    vector<ll> right;

    for (ll i = l - 1; i < r; i++)
      s.pb(a[i]);

    for (ll i = 0; i < l - 1; i++)
      left.pb(a[i]);
    for (ll i = r; i < n; i++)
      right.pb(a[i]);

    sort(all(s), greater<>());
    sort(all(left));
    sort(all(right));
    ll i = 0, j = 0, sum = 0;
    sum = accumulate(all(s), (ll)0);

    ll temp = sum;
    while (i < left.size()) {
      if (j < s.size() and left[i] < s[j]) {
        temp -= s[j];
        temp += left[i];
        i++;
        j++;
      } else {
        break;
      }
    }
    i = 0, j = 0;

    ll temp1 = sum;
    while (i < right.size()) {
      if (j < s.size() and right[i] < s[j]) {
        temp1 -= s[j];
        temp1 += right[i];
        i++;
        j++;
      } else {
        break;
      }
    }
    vector<ll> ans = {sum, temp1, temp};

    cout << *min_element(all(ans)) << endl;

    // debug(sum)
  }

  return 0;
}