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

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

using namespace std;



#define LOCAL

//#define ONLINE_JUDGE



// Type Definitions

typedef long long ll;

typedef vector<int> vi;

typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

typedef vector<pii> vpii;

typedef vector<pll> vpll;

typedef vector<string> vs;

typedef vector<char> vc;

typedef vector<vector<int>> vvi;

typedef vector<vector<ll>> vvll;

typedef vector<vector<char>> vvc;

typedef vector<vector<pii>> vvpii;



//modulo

constexpr long long MOD = (1e9)+7;

ll mod(ll a){return (a%MOD+MOD)%MOD;}

ll add(ll a,ll b){return mod(mod(a)+mod(b));}

ll sub(ll a,ll b){return mod(mod(a)-mod(b));}

ll mul(ll a, ll b){return mod(mod(a)*mod(b));}

ll binpow(ll a, ll b){ a=mod(a);ll res=1;while(b>0) {if(b&1) res=mul(res, a);a=mul(a, a);b>>=1;}return res;}

ll inv(ll x){return binpow(x,MOD-2);}

ll divmod(ll a, ll b){return mul(a,inv(b));}



vi linear_inverse(int n){vi arr(n+1);arr[1]=1; for(int i=2;i<=n;i++){arr[i]=mul(sub(MOD, MOD/i), arr[MOD%i]);}return arr;}

ll extended_gcd(ll a, ll b, ll& x, ll& y){if(a==0){x=0;y=1;return b;}else if(b==0){x=1;y=0;return a;}

else{ll x1, y1; ll g=extended_gcd(b%a, a, x1, y1); x=y1-(b/a)*x1;y=x1;return g;}}



//utilities

const ll INF = 1e18;

const double EPS = 1e-9;

const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};

const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};



vector<ll> infact, fact;

void fill_fact_and_infact(int n)

{

    infact.clear();fact.clear();

    infact.resize(n+1);

    fact.resize(n+1);

    fact[0]=infact[0]=1;

    for(int i=1;i<=n;i++) {fact[i]=mul(fact[i-1], i); infact[i]=inv(fact[i]);}

}



ll P(ll n, ll m)

{

    if(m>n or m<0 or n<0) return 0;

    return mul(fact[n], infact[n-m]);

}



ll C(ll n, ll m)

{

    if(m>n or m<0 || n<0) return 0;

    return mul(P(n, m), infact[m]);

}



vector<vector<int>> readGraph(int n, int m, bool directed = false) {

    vector<vector<int>> adj(n);

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

        int u, v;

        cin >> u >> v;

        --u; --v; // Adjust if nodes are 1-indexed

        adj[u].push_back(v);

        if (!directed) adj[v].push_back(u);

    }

    return adj;

}



//definitions

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

#define jloop(n)            for(int j=0;j<n;j++)

#define all(x)              x.begin(),x.end()

#define pb                  push_back 

#define mp                  make_pair

#define FOR(i, a, b)        for (int i = (a); i < (b); ++i)

#define FORD(i, a, b)       for (int i = (a); i >= (b); --i)

#define FOREACH(it, a)      for (auto it = (a).begin(); it != (a).end(); ++it)





#ifdef LOCAL



#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)



    void debug_out() { std::cerr << std::endl; }



    template<typename T>

    std::string to_string(const T& value) {

        std::ostringstream oss;

        oss << value;

        return oss.str();

    }



    void debug_out(std::string names) {

        std::cerr << names << std::endl;

    }



    template<typename T, typename... Args>

    void debug_out(std::string names, T value, Args... args) {

        // Find position of the first comma

        size_t comma_pos = names.find(',');



        std::string var_name;

        if (comma_pos == std::string::npos) {

            var_name = names;

            names = "";

        } else {

            var_name = names.substr(0, comma_pos);

            names = names.substr(comma_pos + 1);

        }



        // Trim spaces from variable name

        var_name.erase(std::remove_if(var_name.begin(), var_name.end(), ::isspace), var_name.end());



        std::cerr << var_name << " = " << to_string(value);



        if (sizeof...(args) > 0) {

            std::cerr << " ; ";

            debug_out(names, args...); // Recurse with remaining variables

        } else {

            std::cerr << std::endl; // End recursion

        }

    }

#else

    #define debug(...)

#endif





// Overloading >> and << operators for pairs

template<typename T1, typename T2>

istream& operator>>(istream& is, pair<T1, T2>& p) {

    return is >> p.first >> p.second;

}



template<typename T1, typename T2>

ostream& operator<<(ostream& os, const pair<T1, T2>& p) {

    return os << p.first << ' ' << p.second;

}



// Overloading >> and << operators for vectors

template<typename T>

istream& operator>>(istream& is, vector<T>& vec) {

    for (auto& v : vec)

        is >> v;

    return is;

}



template<typename T>

ostream& operator<<(ostream& os, const vector<T>& vec) {

    for (const auto& v : vec)

        os << v << ' ';

    return os;

}



// Overloading >> and << operators for 2D vectors

template<typename T>

istream& operator>>(istream& is, vector<vector<T>>& vec) {

    for (auto& row : vec)

        is >> row; // Uses the overloaded >> operator for vector<T>

    return is;

}



template<typename T>

ostream& operator<<(ostream& os, const vector<vector<T>>& vec) {

    for (const auto& row : vec)

        os << row << '\n'; // Uses the overloaded << operator for vector<T>

    return os;

}



// Reading multiple variables using fold expressions (C++17 and above)

template<typename... Args>

void read(Args&... args) {

    (cin >> ... >> args);

}



// Writing multiple variables

template<typename... Args>

void write(Args... args) {

    ((cout << args << ' '), ...);

    cout << '\n';

}



template<typename T>

vector<vector<T>> vec2d(int n, int m, T val = T()) {

    return vector<vector<T>>(n, vector<T>(m, val));

}



// Uncomment the following for C++11 or C++14

/*

template<typename T>

void read(T& t) {

    cin >> t;

}



template<typename T, typename... Args>

void read(T& t, Args&... args) {

    cin >> t;

    read(args...);

}



template<typename T>

void write(T t) {

    cout << t << ' ';

}



template<typename T, typename... Args>

void write(T t, Args... args) {

    cout << t << ' ';

    write(args...);

}

*/



void solve() 

{

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

    vi a(n); cin>>a;

    l--, r--;

    ll sum = 0; for(int i=l;i<=r;i++) sum+=a[i];

    ll left_sum = sum;

    ll right_sum = sum;

    sort(a.begin(), a.begin()+l);

    sort(a.begin()+l, a.begin()+r+1);

    sort(a.begin()+r+1, a.begin()+n);

    int j = r;

    for(int i=0;i<l and j>=l;i++) {

        if(a[i]<a[j]) {

            left_sum=left_sum-a[j]+a[i];

            j--;

        }

    }

    j=r;

    for(int i=r+1;i<n and j>=l;i++) {

        if(a[i]<a[j]) {

            right_sum = right_sum-a[j]+a[i];

            j--;

        }

    }

    cout<<min(left_sum, right_sum)<<"\n";

}



void preparation()

{

    fill_fact_and_infact(2*(1e5)+1);

}



int main() 

{

    ios_base::sync_with_stdio(false); cin.tie(NULL);

    // #ifndef ONLINE_JUDGE

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

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

    // #endif



    //preparation();

    

    int T; cin>>T;

    while(T--)

    {

       solve();

    }

  

    

    return 0;

}

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

using namespace std;

typedef long long ll;



void solve(){

    ll n,l,r;

    cin >> n >> l >> r;

    ll a[n];

    vector<ll> b,c;

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

        cin >> a[i];

    }

    ll num = r - l + 1;

    ll sum1 = 0;

    ll sum2 = 0;

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

        b.push_back(a[i]);

    }

    //sort(a,a+n);

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

         c.push_back(a[i]);

    }

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

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

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

        sum1+=b[i];

    }

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

        sum2+=c[i];

    }

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

     

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t; 

    cin >> t;

    while(t--)

    solve();

    

    return 0;

}  

 //

// 5 6 4 1 2 3