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

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>

using namespace std;



#define ll long long int

#define ull unsigned long long int

#define ld long double

#define vi vector<int>

#define vll vector<ll>

#define pii pair<int, int>

#define pll pair<ll, ll>

#define mp make_pair

#define pb push_back

#define F first

#define S second

#define ALL(v) v.begin(), v.end()

#define SORT(v) sort(ALL(v))

#define REVERSE(v) reverse(ALL(v))

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

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

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)



const ll MOD = 1e9 + 7;

const ll INF = 1e18;

const ld EPS = 1e-9;



ll gcd(ll a, ll b) {

    while (b != 0) {

        ll temp = b;

        b = a % b;

        a = temp;

    }

    return a;

}



ll lcm(ll a, ll b) {

    return (a / gcd(a, b)) * b;

}



ll mod_exp(ll base, ll exp, ll mod) {

    ll result = 1;

    while (exp > 0) {

        if (exp % 2 == 1) {

            result = (result * base) % mod;

        }

        base = (base * base) % mod;

        exp /= 2;

    }

    return result;

}



bool is_prime(ll n) {

    if (n <= 1) return false;

    if (n <= 3) return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

    for (ll i = 5; i * i <= n; i += 6) {

        if (n % i == 0 || n % (i + 2) == 0) return false;

    }

    return true;

}



void solve() {

    // Your solution code here

    ll n,l,r;

    cin>>n>>l>>r;

    vll pre,seg,next;

    ll a;

    FOR(i,0,n){

        cin>>a;

        if(i<l-1){

          pre.push_back(a);

        }else if(i>=l-1 && i<r){

          seg.push_back(a);

        }else{

            next.push_back(a);

        }

    }



    SORT(pre);

    SORT(seg);

    REVERSE(seg);

    SORT(next);



    ll i = 0;

    ll j = 0;

    ll sum1 = 0;

    ll sum2 = 0;

    ll sol = INT_MIN;

    while(i<pre.size() && j<seg.size()){

        sum1+=pre[i];

        sum2+=seg[j];

        i++;

        j++;

        sol = max(sol,sum2-sum1);

    }

    i = 0;

    j = 0;

    sum1 = 0;

    sum2 = 0;

    while(i<next.size() && j<seg.size()){

       sum1+=next[i];

       sum2+=seg[j];

       sol = max(sol,sum2-sum1);

       i++;

       j++;

    }



    ll sum = accumulate(ALL(seg),0);

    if(sol>0){

        cout<<sum-sol<<endl;

    }else{

        cout<<sum<<endl;

    }

}



int main() {

    FAST_IO;



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}

Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORD(i, a, b) for (int i >= b; --i)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld EPS = 1e-9;

ll gcd(ll a, ll b) {
    while (b != 0) {
        ll temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}

ll mod_exp(ll base, ll exp, ll mod) {
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}

bool is_prime(ll n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}

void solve() {
    // Your solution code here
    ll n,l,r;
    cin>>n>>l>>r;
    vll pre,seg,next;
    ll a;
    FOR(i,0,n){
        cin>>a;
        if(i<l-1){
          pre.push_back(a);
        }else if(i>=l-1 && i<r){
          seg.push_back(a);
        }else{
            next.push_back(a);
        }
    }

    SORT(pre);
    SORT(seg);
    REVERSE(seg);
    SORT(next);

    ll i = 0;
    ll j = 0;
    ll sum1 = 0;
    ll sum2 = 0;
    ll sol = INT_MIN;
    while(i<pre.size() && j<seg.size()){
        sum1+=pre[i];
        sum2+=seg[j];
        i++;
        j++;
        sol = max(sol,1ll*sum2-sum1);
    }
    i = 0;
    j = 0;
    sum1 = 0;
    sum2 = 0;
    while(i<next.size() && j<seg.size()){
       sum1+=next[i];
       sum2+=seg[j];
       sol = max(sol,1ll*sum2-sum1);
       i++;
       j++;
    }

    ll sum = accumulate(ALL(seg),0);
    if(sol>0){
        cout<<1ll*sum-sol<<endl;
    }else{
        cout<<sum<<endl;
    }
}

int main() {
    FAST_IO;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}