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

Solution 1 (runtime: 93 ms):
//DIVYANKAR SHAH//

#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;

typedef long long ll;

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

#define N 1000000

#define MOD 1000000007

#define pb push_back

#define SORT(v) sort(v.begin(), v.end())

#define count_setBits __builtin_popcount

#define count_setBitsll __builtin_popcountll

vector<bool> sieve(N+1);

vector<int> spf(N+1);



//----------------INPUT/OUTPUT--------------//

void input(ll n,vector<ll>&a){

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

}



void debug(vector<ll>&a){

    cout<<"[ ";

    for(int i=0; i<a.size(); i++){

        cout<<a[i]<<" ";

    }

    cout<<"]"<<'\n';

}

//-----------------------------------------//





//------------BIT-TECH--------------------//

//check if a number is even/odd

bool isEven(int x){

    if(x&1) return false;

    return true;

}



//check power of 2 or not

bool powerOf2(int x){

    return (x && (!(x&(x-1))));

}



//kth bit is set or not

bool isKthBitSet(int x, int k){

    if((x&(1<<k))) return true;

    return false;

}



//Toggle Kth bit

void toggleKthBit(int x, int k){

    x = (x^(1<<k));

}



//unset the kth bit

void unsetKthBit(int x, int k){

    x = (x & (~(1<<k)));

}



//set kth bit

void setKthBit(int x, int k){

    x = (x | (1<<k));

}

//--------------------------------------//





//--------------------NUMBER-THEORY-----------------------//

//lcm

ll lcm(ll a,ll b){

    ll g=__gcd(a,b);

    return (a*b/g);

}



//binary exponentiation (a^b)%m

long long binpow(long long a, long long b, long long m) {

    a %= m;

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a % m;

        a = a * a % m;

        b >>= 1;

    }

    return res;

}



//sieve creation

void createSieve(){

    for(int i=2; i<=N; i++){

        sieve[i]=true;

    }



    for(int i=2; i*i<=N; i++){

        if(sieve[i]){

            for(int j=i*i; j<=N; j+=i){

                sieve[j]=false;

            }

        }

    }

}



//sieve for prime

void sieveForPrimeFactors(){

    for(int i=2; i<=N; i++){

        spf[i]=i;

    }



    for(int i=2; i*i<=N; i++){

        if(spf[i]==i){

            for(int j=i*i; j<=N; j+=i){

                if(spf[j]==j) spf[j]=i;

            }

        }

    }

}



//prime factorization

vector<int> primeFactors(int n){

    vector<int> result;

    while(n>1){

        result.push_back(spf[n]);

        n/=spf[n];

    }

    if(n>1) result.push_back(n);

    return result;

}



//finding divisors of a number (1<=number<=1e9)

vector<int> findDivisors(int n){

    vector<int> divisors;

    for(int i=2; i*i<=n; i++){

        if(n%i==0){

            divisors.push_back(i);

            if(n/i!=i){

                divisors.push_back(n/i);

            }

        }

    }



    return divisors;

}

//----------------------------------------------------//





//-------------------STRING----------------------------//

//checking for a substring in a string

int isSubstringPresent(string substr, string &s){

    if(s.find(substr)!=string::npos){

        return s.find(substr); //returning the starting index of substr in s.

    }

    return -1;

}



// calculation of Z arr

// Z[i] = length of the longest substring starting from i which is also a prefix of s

vector<int> z_function(string s){

    int n = s.size();

    vector<int> z(n,0);

    int left = 0, right = 0;

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

        if(i>right){

            left = right = i;

            while(right<n && s[right]==s[right-left]){

                right++;

            }

            z[i] = right-left;

            right--;

        }

        else{

            int k = i-left;

            if(z[k]<right-i+1){

                z[i] = z[k];

            }

            else{

                left = i;

                while(right<n && s[right]==s[right-left]){

                    right++;

                }

                z[i] = right-left;

                right--;

            }

        }

    }

    return z;

}



// LPS array

// LPS[i] = length of the longest proper prefix which is also a suffix of s[0...i]

vector<int> compute_lps(string s){

    int n = s.size();

    vector<int> lps(n,0);

    int len = 0;

    lps[0] = 0;

    int i = 1;

    while(i<n){

        if(s[i]==s[len]){

            len++;

            lps[i] = len;

            i++;

        }

        else{

            if(len!=0){

                len = lps[len-1];

            }

            else{

                lps[i] = 0;

                i++;

            }

        }

    }

    return lps;

}



// KMP algorithm

// returns the starting index of the substring in the string

int KMP(string &txt, string &pat){

    int n = txt.size();

    int m = pat.size();

    vector<int> lps = compute_lps(pat);

    int i = 0, j = 0;

    while(i<n){

        if(txt[i]==pat[j]){

            i++;

            j++;

        }

        if(j==m){

            return i-j;

        }

        else if(i<n && txt[i]!=pat[j]){

            if(j!=0){

                j = lps[j-1];

            }

            else{

                i++;

            }

        }

    }

    return -1;

}

//-----------------------------------------------------//



bool allEqual(vector<ll>&v){

    if(equal(v.begin() + 1, v.end(), v.begin())) return true;

    return false;

}



// Points To Remember:

// 1. Think Greedy

// 2. Think Brute Force

// 3. Think solution in reverse order

// 4. Think DP [ check constraints carefully ]

// 5. Check base cases for DP and prove solution for Greedy

// 6. Think Graph

// 7. ceil a/b=(a+b-1)/b do remember

// 8. Remember to convert size() to int!! Causes creji errors!

// 9. XOR is invertible to itself.

// 10. If x = a mod b then a mod 2b = x or x+a

// 11. (a+b)modc = (a+b-c)modc



void solve(){

    int n,l,r;

    cin>>n>>l>>r;

    vector<int> a(n);

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

    l--, r--;

    vector<ll> temp1, temp2;

    for(int i=0; i<=r; i++) temp1.push_back(a[i]);

    for(int i=l; i<n; i++) temp2.push_back(a[i]);

    SORT(temp1);

    SORT(temp2);

    ll ans1 = accumulate(temp1.begin(), temp1.begin()+(r-l+1), 0LL);

    ll ans2 = accumulate(temp2.begin(), temp2.begin()+(r-l+1), 0LL);

    cout << min(ans1, ans2) << '\n';

}



int main()

{

    ios::sync_with_stdio(0);cin.tie(0);

    #ifndef ONLINE_JUDGE

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

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

    #endif



    int t;

    cin>>t;

    while(t--){

        solve();

    }



    return 0;

}

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

#include <string>

#include <vector>

#include <unordered_map>

#include <algorithm>

#include <map>

#include <set>

#include <functional>

#include <queue>

#include <bitset>

#include <stack>

#include <iomanip>

#include <cstring>

#include <cmath>

#include <utility>

#define ll long long

#define PII pair<int,int>

#define N 15

using namespace std;

void solve(){

	int n,l,r;

	cin >> n >> l >> r;

	vector<int>v(n+5);

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

	vector<int>lr,v1,v2;

	ll ans = 0;

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

		ans += v[i];

		lr.push_back(v[i]);

	}

	ll tot1 = ans,tot2 = ans;

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

	// 1.1到r

	for (int i = 1; i < l; i++) v1.push_back(v[i]);

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

	int plr = r-l,pv1 = 0;

	while (plr >= 0 && pv1 < v1.size()){

		if (lr[plr] > v1[pv1]){

			tot1 = tot1-lr[plr]+v1[pv1];

			plr--;

			pv1++;

		}

		else break;

	}

	// 2.l到n

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

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

	plr = r-l;

	int pv2 = 0;

	while (plr >= 0 && pv2 < v2.size()){

		if (lr[plr] > v2[pv2]){

			tot2 = tot2-lr[plr]+v2[pv2];

			plr--;

			pv2++;

		}

		else break;

	}

//	cout << "ans: " << ans << ",tot1: " << tot1 << ",tot2: " << tot2 << endl;

	ans = min(ans,min(tot1,tot2));

	cout << ans << "\n";

}

int main(){

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

	int t = 1;

	cin >> t;

	while (t--) solve();

	return 0;

}