Problem: 2063B - Subsequence Update
Language: c++17 

Code 1:
#include <algorithm>

#include <array>

#include <iomanip>

#include <iostream>

#include <cmath>

#include <cstdint>

#include <numeric>

#include <map>

#include <set>

#include <string>

#include <vector>



using namespace std;



int64_t min_sum(const vector<int64_t>& lr, const vector<int64_t>& other) {

    int64_t diff = 0;



    for (int i = 0; i < min(lr.size(), other.size()); i++) {

        // cout << "loop: " << other[i] << " " << lr[i] << endl;

        if (other[i] < lr[i]) diff += (lr[i] - other[i]);

    }

    // cout << diff << endl;

    return diff;

}

void solve() {

    // Read input

    int n, l, r;

    cin >> n >> l >> r;

    l--; r--;

    vector<int64_t> a(n);

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

        cin >> a[i];

    }



    // Solve the problem here

    vector<int64_t> lr;

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

        lr.push_back(a[i]);

    }

    sort(lr.begin(), lr.end(), std::greater<int64_t>());



    int64_t sum = accumulate(lr.begin(), lr.end(), 0);

    // cout << sum << endl;

    vector<int64_t> bl;

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

        bl.push_back(a[i]);

    }

    sort(bl.begin(), bl.end());



    vector<int64_t> ar;

    for (int i = r + 1; i < n; i++) {

        ar.push_back(a[i]);

    }

    sort(ar.begin(), ar.end());



    sum = min(sum, sum - min_sum(lr, bl));

    sum = min(sum, sum - min_sum(lr, ar));

    // Print output

    cout << sum << endl;

}



int main() {

    // freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout << setprecision(10);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}

Code 2:
#include <algorithm>

#include <array>

#include <iomanip>

#include <iostream>

#include <cmath>

#include <cstdint>

#include <numeric>

#include <map>

#include <set>

#include <string>

#include <vector>



using namespace std;



int64_t min_sum(const vector<int64_t>& lr, const vector<int64_t>& other) {

    int64_t diff = 0;



    for (int i = 0; i < min(lr.size(), other.size()); i++) {

        // cout << "loop: " << other[i] << " " << lr[i] << endl;

        if (other[i] < lr[i]) diff += (lr[i] - other[i]);

    }

    // cout << diff << endl;

    return diff;

}

void solve() {

    // Read input

    int n, l, r;

    cin >> n >> l >> r;

    l--; r--;

    vector<int64_t> a(n);

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

        cin >> a[i];

    }



    // Solve the problem here

    vector<int64_t> lr;

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

        lr.push_back(a[i]);

    }

    sort(lr.begin(), lr.end(), std::greater<int64_t>());



    int64_t sum = accumulate(lr.begin(), lr.end(), int64_t(0));

    // cout << sum << endl;

    vector<int64_t> bl;

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

        bl.push_back(a[i]);

    }

    sort(bl.begin(), bl.end());



    vector<int64_t> ar;

    for (int i = r + 1; i < n; i++) {

        ar.push_back(a[i]);

    }

    sort(ar.begin(), ar.end());



    sum = min(min(sum, sum - min_sum(lr, bl)), sum - min_sum(lr, ar));

    // Print output

    cout << sum << endl;

}



int main() {

    // freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);



    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    cout << setprecision(10);



    int t;

    cin >> t;

    while (t--) {

        solve();

    }



    return 0;

}

Answer: 2