Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
//******************************************************//
//*                AUTHOR: NAMAN OSTWAL                *//
//******************************************************//
//______________________________________________________________________________________________________//
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
long long int mod = 1e9+7;
const int N = 1e6+7;
vector<bool> isprime(N, true);

inline void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void print(vector<ll>&v) { for(auto it : v) cout<<it<<' '; }
void sort(vector < ll > &v) { sort(v.begin() , v.end()); }
void rsort(vector < ll > &v) { sort(v.begin() , v.end(), greater<int>()); }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
ll lcm(ll a, ll b) { return ((a * b) / (__gcd(a,b))); }

ll bin_expo(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1) {
            ans = (ans * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans % mod;
}

void sieve_of_eratosthenes() {
    isprime[0] = isprime[1] = false;
    for(int i = 2; i<=N; i++) {
        if(isprime[i] == true) {
            for(int j = 2*i; j<=N; j+=i) {
                isprime[j] = false;
            }
        }
    }
}

bool ispal(string s) {
    int n = s.size();
    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[n - i - 1]) {
            return false;
        }
    }
    return true;
}

void DFSUtil(ll node, vector<vector<ll>>& adj, vector<bool>& visited, vector<ll>& dfs) {
    visited[node] = true;
    dfs.push_back(node);
    for (ll neighbor : adj[node]) {
        if (!visited[neighbor]) {
            DFSUtil(neighbor, adj, visited, dfs);
        }
    }
}

void dfs(vector<vector<ll>>& adj, ll n, vector<ll>& dfs) {
    vector<bool> visited(n, false);
    for (ll i = 0; i < n; ++i) {
        if (!visited[i]) {
            DFSUtil(i, adj, visited, dfs);
        }
    }
}

void bfs(vector<vector<ll>>& adj, ll n, vector<ll>& bfs) {
    queue<ll> q;
    vector<bool> visited(n, false);
    visited[0] = true;
    q.push(0);
    while (!q.empty()) {
        ll node = q.front();
        q.pop();
        bfs.push_back(node);
        for (auto it : adj[node]) {
            if (!visited[it]) {
                visited[it] = true;
                q.push(it);
            }
        }
    }
}

int main() {
    fast_io();
    int t;
    cin >> t;
    while (t--) {
        ll n, l, r;
        cin >> n >> l >> r;
        vector < ll > v(n);
        for(int i = 0 ; i < n ; i++) cin >> v[i];

        sort(v);
        ll ct = r - l + 1, ans = 0;
        for(int i = 0 ; i < n && ct > 0; i++) {
            ans += v[i];
            ct--;
        }

        cout << ans << endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 8):
//******************************************************//
//*                AUTHOR: NAMAN OSTWAL                *//
//******************************************************//
//______________________________________________________________________________________________________//
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
long long int INF = 1e9+7;
long long int mod = 1e9+7;
const int N = 1e6+7;
vector<bool> isprime(N, true);

inline void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void print(vector<ll>&v) { for(auto it : v) cout<<it<<' '; }
void sort(vector < ll > &v) { sort(v.begin() , v.end()); }
void rsort(vector < ll > &v) { sort(v.begin() , v.end(), greater<int>()); }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) { return ((a % mod) + (b % mod) + mod) % mod; }
ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
ll lcm(ll a, ll b) { return ((a * b) / (__gcd(a,b))); }

ll bin_expo(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1) {
            ans = (ans * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans % mod;
}

void sieve_of_eratosthenes() {
    isprime[0] = isprime[1] = false;
    for(int i = 2; i<=N; i++) {
        if(isprime[i] == true) {
            for(int j = 2*i; j<=N; j+=i) {
                isprime[j] = false;
            }
        }
    }
}

bool ispal(string s) {
    int n = s.size();
    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[n - i - 1]) {
            return false;
        }
    }
    return true;
}

void DFSUtil(ll node, vector<vector<ll>>& adj, vector<bool>& visited, vector<ll>& dfs) {
    visited[node] = true;
    dfs.push_back(node);
    for (ll neighbor : adj[node]) {
        if (!visited[neighbor]) {
            DFSUtil(neighbor, adj, visited, dfs);
        }
    }
}

void dfs(vector<vector<ll>>& adj, ll n, vector<ll>& dfs) {
    vector<bool> visited(n, false);
    for (ll i = 0; i < n; ++i) {
        if (!visited[i]) {
            DFSUtil(i, adj, visited, dfs);
        }
    }
}

void bfs(vector<vector<ll>>& adj, ll n, vector<ll>& bfs) {
    queue<ll> q;
    vector<bool> visited(n, false);
    visited[0] = true;
    q.push(0);
    while (!q.empty()) {
        ll node = q.front();
        q.pop();
        bfs.push_back(node);
        for (auto it : adj[node]) {
            if (!visited[it]) {
                visited[it] = true;
                q.push(it);
            }
        }
    }
}

int main() {
    fast_io();
    int t;
    cin >> t;
    while (t--) {
        ll n, l, r;
    	cin >> n >> l >> r;
    	vector<ll> a(n);
    	for (int i = 0; i < n; i++) cin >> a[i];
    	l--, r--;
    	ll len = r - l + 1;
    	vector<ll> pre(len + 1, INF), suf(len + 1, INF), mid(len + 1, INF);
    	sort(a.begin(), a.begin() + l);
    	sort(a.begin() + l, a.begin() + r + 1);
    	reverse(a.begin() + l, a.begin() + r + 1);
    	sort(a.begin() + r + 1, a.end());
    	suf[0] = pre[0] = mid[0] = 0;
    	for (int i = 0; i < min(len, l); i++) {
    		pre[i + 1] = pre[i] + a[i];
    	}
    	for(int i = l; i <= r; i++) {
    		mid[i - l + 1] = mid[i - l] + a[i];
    	}
    	for(int i = r + 1; i < min(r + 1 + len, n); i++) {
    		suf[i - r] = suf[i - r - 1] + a[i];
    	}
    	ll ans = 0;
    	for(int i = 1; i <= len; i++) {
    		ans = max(ans, mid[i] - suf[i]);
    		ans = max(ans, mid[i] - pre[i]);
    	}
    	ans = -ans;
    	for(int i = l; i <= r; i++) ans += a[i];
    	cout << ans << "\n";
    }
    return 0;
}