Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
    int z;
    cin >> z;
    while(z--) {
        int n , l ,r ;
        cin >> n >> l >> r;
        vector<int> a(n);
        // take in all elements in vector
        for(int i = 0 ; i < n ; i++){
            cin >> a[i];
        }

        vector<int> v1(a.begin(), a.begin() + l - 1);
        vector<int> v2(a.begin() + l - 1, a.begin() + r);
        vector<int> v3(a.begin() + r, a.end());

        // sort all vectors
        sort(v1.begin(), v1.end());
        sort(v2.begin(), v2.end());
        sort(v3.begin(), v3.end());

        int s1 = 0;
        if(v1.size() != 0) {
            int it = 0;
            for(int i = v2.size() - 1 ; i >= 0; i--) {
                if(it <= v1.size() - 1) {
                    if(v2[i] > v1[it]) {
                        s1 += v1[it];
                    } else {
                        s1 += v2[i];
                    }
                    it++;
                }
            }
        }

        if(v2.size() > v1.size()) {
            for(int i = 0; i < v2.size()-v1.size(); i++) {
                s1 += v2[i];
            }
        }

        int s2 = 0;
        if(v3.size() != 0) {
            int it = 0;
            for(int i = v2.size() - 1 ; i >= 0; i--) {
                if(it <= v3.size() - 1) {
                    if(v2[i] > v3[it]) {
                        s2 += v3[it];
                    } else {
                        s2 += v2[i];
                    }
                    it++;
                }
            }
        }

        if(v2.size() > v3.size()) {
            for(int i = 0; i < v2.size()-v3.size(); i++) {
                s2 += v2[i];
            }
        }

        if(s1 < s2) {
            cout << s1 << endl;
        } else {
            cout << s2 << endl;
        }
    }

    return 0;
}


Submission (verdict: Wrong answer on test 8):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
    int z;
    cin >> z;
    while(z--) {
        int n , l ,r ;
        cin >> n >> l >> r;
        vector<int> a(n);
        // take in all elements in vector
        for(int i = 0 ; i < n ; i++){
            cin >> a[i];
        }

        vector<int> v1(a.begin(), a.begin() + l - 1);
        vector<int> v2(a.begin() + l - 1, a.begin() + r);
        vector<int> v3(a.begin() + r, a.end());

        // sort all vectors
        sort(v1.begin(), v1.end());
        sort(v2.begin(), v2.end());
        sort(v3.begin(), v3.end());

        int s1 = 0;
        if(v1.size() != 0) {
            int it = 0;
            for(int i = v2.size() - 1 ; i >= 0; i--) {
                if(it <= v1.size() - 1) {
                    if(v2[i] > v1[it]) {
                        s1 += v1[it];
                    } else {
                        s1 += v2[i];
                    }
                    it++;
                }
            }
        }

        if(v2.size() > v1.size()) {
            for(int i = 0; i < v2.size()-v1.size(); i++) {
                s1 += v2[i];
            }
        }

        int s2 = 0;
        if(v3.size() != 0) {
            int it = 0;
            for(int i = v2.size() - 1 ; i >= 0; i--) {
                if(it <= v3.size() - 1) {
                    if(v2[i] > v3[it]) {
                        s2 += v3[it];
                    } else {
                        s2 += v2[i];
                    }
                    it++;
                }
            }
        }

        if(v2.size() > v3.size()) {
            for(int i = 0; i < v2.size()-v3.size(); i++) {
                s2 += v2[i];
            }
        }

        if(s1 < s2) {
            cout << s1 << endl;
        } else {
            cout << s2 << endl;
        }
    }

    return 0;}