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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define       forn(i, n)             for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
#define            pb                push_back
#define            vi                vector<int>
#define            vvi               vector<vector<int>>
#define            vll               vector<ll>
#define            vvll              vector<vector<ll>>
#define            ll                long long
// #define int long long
void lilAref()
{
 cin.tie(0);
 cout.tie(0);
 ios_base::sync_with_stdio(false);
}

ll modProd(ll a, ll b, ll mod)
{
    if (a < 0)
        a += mod;
    if (b < 0)
        b += mod;
    a *= b;
    if (a >= mod)
        a %= mod;
    return a;
}

ll modPow(int a, ll b,ll mod) {
    int result = 1;
    while (b) {
        if (b & 1)
            result = modProd(result, a,mod);
        a = modProd(a, a,mod);
        b >>= 1;
    }
    return result;
}

vector<ll> divisors(ll n) {
    vector<ll>divis;
    for (ll i = 1;i * i <= n;i++) {
        if (n % i == 0) {
            divis.push_back(i);
            if (n != i * i)divis.push_back(n / i);
        }
    }
    return divis;
}

signed main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    lilAref();
    int tt;cin>>tt;
    while (tt--) {
        int n,l,r;cin>>n>>l>>r;
        vector<int>vec(n);
        for (auto &it:vec)cin>>it;
        sort(all(vec));
        int cnt = r-l+1;
        int tot=0;
        for (int i{};i<cnt;i++) {
            tot+=vec[i];
        }
        cout<<tot<<endl;
    }

}

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

#define       forn(i, n)             for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
#define            pb                push_back
#define            vi                vector<int>
#define            vvi               vector<vector<int>>
#define            vll               vector<ll>
#define            vvll              vector<vector<ll>>
#define            ll                long long
// #define int long long
void lilAref()
{
 cin.tie(0);
 cout.tie(0);
 ios_base::sync_with_stdio(false);
}

ll modProd(ll a, ll b, ll mod)
{
    if (a < 0)
        a += mod;
    if (b < 0)
        b += mod;
    a *= b;
    if (a >= mod)
        a %= mod;
    return a;
}

ll modPow(int a, ll b,ll mod) {
    int result = 1;
    while (b) {
        if (b & 1)
            result = modProd(result, a,mod);
        a = modProd(a, a,mod);
        b >>= 1;
    }
    return result;
}

vector<ll> divisors(ll n) {
    vector<ll>divis;
    for (ll i = 1;i * i <= n;i++) {
        if (n % i == 0) {
            divis.push_back(i);
            if (n != i * i)divis.push_back(n / i);
        }
    }
    return divis;
}

signed main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    lilAref();
    int tt;cin>>tt;
    while (tt--) {
        int n,l,r;cin>>n>>l>>r;
        vector<int>range,left,right;
        ll sum = 0;
        for (int i=1;i<=n;i++) {
            int a;cin>>a;
            if (i<l)
                left.push_back(a);
            else if (i>r)
                right.push_back(a);
            else {
                range.push_back(a);sum+=a;
            }
        }
        sort(all(left));
        sort(all(right));
        sort(all(range));
        int cnt = r-l+1;
        int ltot=sum;
        int rtot= sum;
        int ind=0;
        if (left.size()) {
            for (int i=range.size()-1;i>=0;i--) {
                if (range[i]<left[ind])
                    break;
                ltot-=range[i];
                ltot+=left[ind++];
            }
        }
        ind=0;
        if (right.size()) {
            for (int i=range.size()-1;i>=0;i--) {
                if (range[i]<right[ind])
                    break;
                ltot-=range[i];
                ltot+=right[ind++];
            }
        }
        cout<<min(ltot,rtot)<<endl;
    }

}