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

Solution 1 (runtime: 109 ms):
/**

*    author:  lazyhash(yashkundu)

*    created: 15 Feb, 2025 | 14:56:32

**/

#include <iostream>

#include <vector>

#include <random>

#include <chrono>

#include <algorithm>

 

using namespace std;

 

typedef long long ll;

typedef long double ld;

 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



void __print(int x) {cerr << x;}

void __print(long x) {cerr << x;}

void __print(long long x) {cerr << x;}

void __print(unsigned x) {cerr << x;}

void __print(unsigned long x) {cerr << x;}

void __print(unsigned long long x) {cerr << x;}

void __print(float x) {cerr << x;}

void __print(double x) {cerr << x;}

void __print(long double x) {cerr << x;}

void __print(char x) {cerr << '\'' << x << '\'';}

void __print(const char *x) {cerr << '\"' << x << '\"';}

void __print(const string &x) {cerr << '\"' << x << '\"';}

void __print(bool x) {cerr << (x ? "true" : "false");}



template<typename T, typename V>

void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>

void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>

void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE

#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

#else

#define debug(x...)

#endif



int n, l, r;

vector<ll> a;

vector<ll> lft, rght;

vector<ll> v;





ll calc(vector<ll> x, vector<ll> b) {

    sort(x.rbegin(), x.rend());

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



    // debug(x, b);



    ll del = 0;

    ll cur = 0;

    for(int i=0;i<min(x.size(), b.size());i++) {

        cur += x[i]-b[i];

        del = max(del, cur);

    }

    return del;

}







 

void solve() {

    cin >> n >> l >> r;

    a.resize(n);

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

    lft.clear();

    rght.clear();

    v.clear();

    for(int i=0;i<l-1;i++) lft.push_back(a[i]);

    for(int i=r;i<n;i++) rght.push_back(a[i]);

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



    // debug(lft, rght, v);



    ll del = max(calc(v, lft), calc(v, rght));

    ll sum = 0;

    for(int i=l-1;i<r;i++) sum += a[i];

    sum -= del;

    cout << sum << "\n";



    

}

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

 

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}

/* stuff you should look for

* int overflow, array bounds

* special cases (n=1?)

* do smth instead of nothing and stay organized

* WRITE STUFF DOWN

* DON'T GET STUCK ON ONE APPROACH

* - BenQ

*/

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

#include <vector>

#include <algorithm>

#include <map>

#include <set>

#include <string>

#include <numeric>

using namespace std;



#define ll long long

void solve()

{

    ll n, l, r;

    cin >> n>>l>>r;

    vector<int> a(n);

    ll sum1=0;

    ll sum2=0;

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

    {

        cin >> a[i];

    }

    if(l == 1 && r==n)

    {

        sum1 = accumulate(a.begin(), a.end(), 0LL);

        cout << sum1 << endl;

        return;

    }

    vector<int> b;

    vector<int> c;

    for (ll i = 0; i < r; i++)

    {

        b.push_back(a[i]);

    }

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

    {

        c.push_back(a[i]);

    }

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

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

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

    {

        sum1+=b[i];

    }

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

    {

        sum2+=c[i];

    }

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



}



int32_t main()

{

    ll t;

    cin >> t;

    while (t--)

    {

        solve();

    }

    

    return 0;

}