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

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

// Aliases
using ll = long long;
using ull = unsigned long long;
using ld = long double;

// Constants
constexpr ll INF = 4e18;
constexpr ld EPS = 1e-9;
constexpr ll MOD = 998244353;

// Macros
#define F first
#define S second
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define pb push_back
#define MP make_pair
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)

// Modular arithmetic functions
ll inv(ll i) {
    if (i == 1) return 1;
    return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;
}

ll mod_mul(ll a, ll b) {
    return (a % MOD * b % MOD) % MOD;
}

ll mod_add(ll a, ll b) {
    return (a % MOD + b % MOD) % MOD;
}

ll mod_sub(ll a, ll b) {
    return (a % MOD - b % MOD + MOD) % MOD;
}

ll pwr(ll a, ll b) {
    ll res = 1;
    a %= MOD;
    while (b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

// Fast I/O
istream& operator>>(istream &is, vector<ll> &v) {
    for (auto &x : v) is >> x;
    return is;
}

ostream& operator<<(ostream &os, const vector<ll> &v) {
    for (auto &x : v) os << x << " ";
    return os;
}

// Main logic
void solve() {
  int n, l, r;
    cin >> n >> l >> r;

    // Initialize vectors with size n.
    vector<int> a(n), b(n);

    // Fix the for-loop header and use assignment into already-sized vectors.
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[i] = x;
        b[i] = x;
    }

    l--; 
    r--;

    sort(a.begin() + l, a.end());
    sort(b.begin(), b.begin() + r + 1);

    int val1 = 0;
    int val2 = 0;

    // This loop uses 'i' from 0 to r; 
    // if you intended to sum r-l+1 elements, consider checking your loop range.
    for (int i = 0; i <= r; i++){
        val1 += a[l + i];
        val2 += b[i];
    }
    
    cout << min(val1, val2) << endl;
    return ;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int T;
    cin >> T;

    auto start = high_resolution_clock::now();
    while (T--) {
        solve();
    }
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cerr << "Time: " << duration.count() / 1000 << " ms" << endl;

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>

#include <chrono>

using namespace std;

using namespace chrono;



// Aliases

using ll = long long;

using ull = unsigned long long;

using ld = long double;



// Constants

constexpr ll INF = 4e18;

constexpr ld EPS = 1e-9;

constexpr ll MOD = 998244353;



// Macros

#define F first

#define S second

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

#define allr(x) rbegin(x), rend(x)

#define pb push_back

#define MP make_pair

#define endl '\n'

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



// Modular arithmetic functions

ll inv(ll i) {

    if (i == 1) return 1;

    return (MOD - (MOD / i) * inv(MOD % i) % MOD) % MOD;

}



ll mod_mul(ll a, ll b) {

    return (a % MOD * b % MOD) % MOD;

}



ll mod_add(ll a, ll b) {

    return (a % MOD + b % MOD) % MOD;

}



ll mod_sub(ll a, ll b) {

    return (a % MOD - b % MOD + MOD) % MOD;

}



ll pwr(ll a, ll b) {

    ll res = 1;

    a %= MOD;

    while (b > 0) {

        if (b & 1) res = res * a % MOD;

        a = a * a % MOD;

        b >>= 1;

    }

    return res;

}



// Fast I/O

istream& operator>>(istream &is, vector<ll> &v) {

    for (auto &x : v) is >> x;

    return is;

}



ostream& operator<<(ostream &os, const vector<ll> &v) {

    for (auto &x : v) os << x << " ";

    return os;

}



// Main logic

void solve() {

 int n, l, r;

    cin >> n >> l >> r;

    vector<ll> a(n);

    cin >> a;

    vector<ll> b(n);

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

        b[i] = a[i];

    l--;

    r--;

    sort(a.begin(), a.begin() + r + 1);

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

    ll temp1 = 0;

    ll temp2 = 0;

    for (int i = l; i <= r; i++)

    {

        temp1 += b[i];

    }

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

    {

        temp2 += a[i];

    }

    cout << min(temp1, temp2) << endl;

}



int main() {

    ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    int T;

    cin >> T;



    auto start = high_resolution_clock::now();

    while (T--) {

        solve();

    }

    auto stop = high_resolution_clock::now();

    auto duration = duration_cast<microseconds>(stop - start);

    cerr << "Time: " << duration.count() / 1000 << " ms" << endl;



    return 0;

}