Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)

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

using namespace std;



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

#define ll long long

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

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



const int MOD = 1e9 + 7;

const int MAXN = 1e6 + 5;



vector<ll> fact(MAXN), invFact(MAXN);



// Utility Functions

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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



// Base case: print a single value (non-vector type)

template <typename T>

void printVector(const T& value) {

    cout << value << ' ';

}



// Recursive case: print nested vectors

template <typename T>

void printVector(const vector<T>& vec) {

    cout << '[';

    for (const auto& element : vec) {

        printVector(element);  // Recursively print each element

    }

    cout << ']';

}



// Function to read input into a vector

template<typename T>

void read_vec(vector<T>& v) {

    for (auto& elem : v) cin >> elem;

}



// Binary exponentiation function

ll binpow(ll a, ll b) {

    ll result = 1;

    a %= MOD;

    while (b > 0) {

        if (b % 2 == 1) result = (result * a) % MOD;

        a = (a * a) % MOD;

        b /= 2;

    }

    return result;

}



ll modDivide(ll a, ll b) {

    ll b_inv = binpow(b, MOD - 2);

    return (a * b_inv) % MOD;

}



// Precompute factorials

void precomputeFactorials() {

    fact[0] = 1;

    for (int i = 1; i < MAXN; ++i) fact[i] = (fact[i - 1] * i) % MOD;

    invFact[MAXN - 1] = binpow(fact[MAXN - 1], MOD - 2);

    for (int i = MAXN - 2; i >= 0; --i) invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;

}



// Combination function nCr using precomputed factorials

ll combination(int n, int r) {

    if (r > n || r < 0) return 0;

    return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;

}



// Permutation function nPr using precomputed factorials

ll permutation(int n, int r) {

    if (r > n || r < 0) return 0;

    return fact[n] * invFact[n - r] % MOD;

}



// Function to multiply two matrices under modulo MOD

vector<vector<ll>> multiply(const vector<vector<ll>> &A, const vector<vector<ll>> &B) {

    vector<vector<ll>> result(A.size(), vector<ll>(A.size(), 0));

    forn(i, A.size()) {

        forn(j, A.size()) {

            forn(k, A.size())

                result[i][j] = (result[i][j] + A[i][k] * B[k][j]) % MOD;

        }

    }

    return result;

}



// Function to return the prime factors of a given number n

vector<ll> getPrimeFactors(ll n) {

    vector<ll> primeFactors;

    while (n % 2 == 0) {

        primeFactors.push_back(2);

        n /= 2;

    }

    for (ll i = 3; i * i <= n; i += 2) {

        while (n % i == 0) {

            primeFactors.push_back(i);

            n /= i;

        }

    }

    if (n > 2) primeFactors.push_back(n);

    return primeFactors;

}



// Euler Totient Function (ETF) counts the number of positive integers upto n which are co-prime to n

// For any prime P, ETF(P) = P - 1

// For any number y which is prime power of P -> y = P^x, ETF(y) = P^x (total number of integers upto y) - (P^x / P) (number of multiple of P)

// Euler's Totient function

ll eulerTotient(ll n) {

    ll result = n;

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

        if (n % i == 0) {

            while (n % i == 0) n /= i;

            result -= result / i;

        }

    }

    if (n > 1) result -= result / n;

    return result;

}



// Multiplicative property holds for functions F(N * M) = F(N) * F(M) where gcd(N, M) = 1.

// Also to get the modulo multiplicative inverse of a number this should hold gcd(x, y) = 1 for {x * m = 1 mod y}, m is modulo multiplicative inverse

// total numbers of divisors of any number use multiplicative property -> break number inot it's prime factors, 

// then for any prime factor P^x there will be (x + 1) divisors and using multiplicative property get the total divisors of any number 

// Div(n) = (x1 + 1) * (x2 + 1) * ... * (xn + 1)



// Function to return all divisors of a given number n

vector<ll> getDivisors(ll n) {

    vector<ll> divisors;

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

        if (n % i == 0) {

            divisors.push_back(i);

            if (i != n / i) divisors.push_back(n / i);

        }

    }

    return divisors;

}



// [ F(n1)  F(n2) ] * Matrix -> [ F(n2)  F(n3) ]

// Function to perform matrix exponentiation (A^power) under modulo MOD

vector<vector<ll>> matrixExpo(vector<vector<ll>> A, ll power) {

    vector<vector<ll>> result(A.size(), vector<ll>(A.size(), 0));

    forn(i, A.size()) result[i][i] = 1;  // Identity matrix

    while (power > 0) {

        if (power % 2 == 1) result = multiply(result, A);

        A = multiply(A, A);

        power /= 2;

    }

    return result;

}



// Solve function to encapsulate the logic

void solve() {

    ll n, l, r;

    cin>>n>>l>>r;

    vector<ll> arr(n);

    read_vec(arr);

    sort(all(arr));

    ll size = r - l + 1, total = 0;

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

        total += arr[i];

    }

    cout<<total<<"\n";

}



int main() {

    fastio;



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



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

#define ll long long

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

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



const int MOD = 1e9 + 7;

const int MAXN = 1e6 + 5;



vector<ll> fact(MAXN), invFact(MAXN);



// Utility Functions

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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



// Base case: print a single value (non-vector type)

template <typename T>

void printVector(const T& value) {

    cout << value << ' ';

}



// Recursive case: print nested vectors

template <typename T>

void printVector(const vector<T>& vec) {

    cout << '[';

    for (const auto& element : vec) {

        printVector(element);  // Recursively print each element

    }

    cout << ']';

}



// Function to read input into a vector

template<typename T>

void read_vec(vector<T>& v) {

    for (auto& elem : v) cin >> elem;

}



// Binary exponentiation function

ll binpow(ll a, ll b) {

    ll result = 1;

    a %= MOD;

    while (b > 0) {

        if (b % 2 == 1) result = (result * a) % MOD;

        a = (a * a) % MOD;

        b /= 2;

    }

    return result;

}



ll modDivide(ll a, ll b) {

    ll b_inv = binpow(b, MOD - 2);

    return (a * b_inv) % MOD;

}



// Precompute factorials

void precomputeFactorials() {

    fact[0] = 1;

    for (int i = 1; i < MAXN; ++i) fact[i] = (fact[i - 1] * i) % MOD;

    invFact[MAXN - 1] = binpow(fact[MAXN - 1], MOD - 2);

    for (int i = MAXN - 2; i >= 0; --i) invFact[i] = (invFact[i + 1] * (i + 1)) % MOD;

}



// Combination function nCr using precomputed factorials

ll combination(int n, int r) {

    if (r > n || r < 0) return 0;

    return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;

}



// Permutation function nPr using precomputed factorials

ll permutation(int n, int r) {

    if (r > n || r < 0) return 0;

    return fact[n] * invFact[n - r] % MOD;

}



// Function to multiply two matrices under modulo MOD

vector<vector<ll>> multiply(const vector<vector<ll>> &A, const vector<vector<ll>> &B) {

    vector<vector<ll>> result(A.size(), vector<ll>(A.size(), 0));

    forn(i, A.size()) {

        forn(j, A.size()) {

            forn(k, A.size())

                result[i][j] = (result[i][j] + A[i][k] * B[k][j]) % MOD;

        }

    }

    return result;

}



// Function to return the prime factors of a given number n

vector<ll> getPrimeFactors(ll n) {

    vector<ll> primeFactors;

    while (n % 2 == 0) {

        primeFactors.push_back(2);

        n /= 2;

    }

    for (ll i = 3; i * i <= n; i += 2) {

        while (n % i == 0) {

            primeFactors.push_back(i);

            n /= i;

        }

    }

    if (n > 2) primeFactors.push_back(n);

    return primeFactors;

}



// Euler Totient Function (ETF) counts the number of positive integers upto n which are co-prime to n

// For any prime P, ETF(P) = P - 1

// For any number y which is prime power of P -> y = P^x, ETF(y) = P^x (total number of integers upto y) - (P^x / P) (number of multiple of P)

// Euler's Totient function

ll eulerTotient(ll n) {

    ll result = n;

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

        if (n % i == 0) {

            while (n % i == 0) n /= i;

            result -= result / i;

        }

    }

    if (n > 1) result -= result / n;

    return result;

}



// Multiplicative property holds for functions F(N * M) = F(N) * F(M) where gcd(N, M) = 1.

// Also to get the modulo multiplicative inverse of a number this should hold gcd(x, y) = 1 for {x * m = 1 mod y}, m is modulo multiplicative inverse

// total numbers of divisors of any number use multiplicative property -> break number inot it's prime factors, 

// then for any prime factor P^x there will be (x + 1) divisors and using multiplicative property get the total divisors of any number 

// Div(n) = (x1 + 1) * (x2 + 1) * ... * (xn + 1)



// Function to return all divisors of a given number n

vector<ll> getDivisors(ll n) {

    vector<ll> divisors;

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

        if (n % i == 0) {

            divisors.push_back(i);

            if (i != n / i) divisors.push_back(n / i);

        }

    }

    return divisors;

}



// [ F(n1)  F(n2) ] * Matrix -> [ F(n2)  F(n3) ]

// Function to perform matrix exponentiation (A^power) under modulo MOD

vector<vector<ll>> matrixExpo(vector<vector<ll>> A, ll power) {

    vector<vector<ll>> result(A.size(), vector<ll>(A.size(), 0));

    forn(i, A.size()) result[i][i] = 1;  // Identity matrix

    while (power > 0) {

        if (power % 2 == 1) result = multiply(result, A);

        A = multiply(A, A);

        power /= 2;

    }

    return result;

}



// Solve function to encapsulate the logic

void solve() {

    ll n, l, r;

    cin>>n>>l>>r;

    vector<ll> arr(n);

    read_vec(arr);

    if(2 * (r - l + 1) <= n){

        vector<ll> res, a;

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

            if(i >= l && i <= r){

                a.push_back(arr[i]);

                continue;

            }

            res.push_back(arr[i]);

        }

        sort(all(res));

        sort(all(a));

        ll j = 0, ans = 0;

        for(int i = 0; i < a.size() && j < res.size(); i++){

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

                ans += a[i];

            }

            else{

                ans += res[j];

                j++;

            }

        }

        cout<<ans<<"\n";

    }

    else{

        sort(all(arr));

        ll size = r - l + 1, total = 0;

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

            total += arr[i];

        }

        cout<<total<<"\n";

    }

}



int main() {

    fastio;



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}