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

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

using namespace std;



#define first x

#define second y



typedef long long ll;

typedef pair<int,int> PII;



const int N=2e4+10,inf=0x3f3f3f3f;



bool cmp(ll a,ll b)

{

	return a>b;

}



void solve()

{

	ll n,l,r;

	cin>>n>>l>>r;

	ll sum1=0,sum2=0,ans=1e18;

	vector<ll> a,b,c;

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

	{

		ll t;

		cin>>t;

		if(i>=l&&i<=r) sum1+=t,sum2+=t,a.push_back(t);

		else if(i>r) b.push_back(t);

		else c.push_back(t);

	}



	if(a.size()==n){

		cout<<sum1<<endl;

		return;

	}

	else if(b.size()+c.size()==n){

		cout<<0<<endl;

		return;

	}

	

	sort(a.begin(),a.end(),cmp);

	if(b.size()!=0) sort(b.begin(),b.end());

	if(c.size()!=0) sort(c.begin(),c.end());

	

	ll i1=0,i2=0,i3=0;

	while(i1<a.size()&&i2<b.size())

	{

		if(a[i1]>b[i2]) sum1-=a[i1++],sum1+=b[i2++]; 

		else break; 

	}



	i1=0;

	while(i1<a.size()&&i3<c.size())

	{

		if(a[i1]>c[i3]) sum2-=a[i1++],sum2+=c[i3++];

		else break;

	}

	ans=min(ans,sum1);

	ans=min(sum2,ans);

	cout<<ans<<endl;

}



int main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	int T=1;

	cin>>T;

	

	while(T--)

	{

		solve();

	}

}

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



using namespace std;



#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>



template <class T>

using ordered_set =

    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,

                     __gnu_pbds::tree_order_statistics_node_update>;



#define TRACE(x) cerr << __LINE__ << ": " << #x << " = " << x << endl

#define _ << " _ " <<



template <class T, class U> ostream &operator<<(ostream &o, pair<T, U> x) {

  return o << "(" << x.first << ", " << x.second << ")";

}

template <class> struct is_container : false_type {};

template <class... Ts> struct is_container<vector<Ts...>> : true_type {};

template <class... Ts> struct is_container<map<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_map<Ts...>> : true_type {};

template <class... Ts> struct is_container<set<Ts...>> : true_type {};

template <class... Ts> struct is_container<unordered_set<Ts...>> : true_type {};

template <class... Ts> struct is_container<multiset<Ts...>> : true_type {};

template <class... Ts>

struct is_container<unordered_multiset<Ts...>> : true_type {};

template <class T, class = typename enable_if<is_container<T>::value>::type>

ostream &operator<<(ostream &o, T x) {

  int f = 1;

  o << "{";

  for (auto y : x) {

    o << (f ? "" : ", ") << y;

    f = 0;

  }

  return o << "}";

}



typedef long long llint;



const int MAXN = 1e5 + 10;



int t, n, l, r;

int a[MAXN];



void solve() {

  scanf("%d%d%d", &n, &l, &r);

  --l;

  --r;

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

    scanf("%d", &a[i]);



  llint sum = 0;

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

    sum += (llint)a[i];



  vector<int> A, B, C;

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

    if (i < l)

      A.push_back(a[i]);

    if (l <= i && i <= r)

      B.push_back(a[i]);

    if (i > r)

      C.push_back(a[i]);

  }



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

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

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



  reverse(B.begin(), B.end());



  llint dl = 0, dr = 0, sol = sum;

  for (int i = 0; i < (int)min(A.size(), B.size()); ++i)

    if (A[i] < B[i])

      dl += (llint)(B[i] - A[i]);



  for (int i = 0; i < (int)min(C.size(), B.size()); ++i)

    if (C[i] < B[i])

      dr += (llint)(B[i] - C[i]);



  printf("%lld\n", sum - max(dl, dr));

}



int main(void) {

  scanf("%d", &t);

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

    solve();

  }

  return 0;

}