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

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <vector>

#include <algorithm>



using namespace std;



int solve(int n, vector<int>& sequence, int l, int r) {

    vector<int> sorted_seq = sequence;

    sort(sorted_seq.begin(), sorted_seq.end()); // Sort the entire array



    int segment_size = r - l + 1;

    int min_sum = 0;



    // Take the smallest `segment_size` elements from the sorted array

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

        min_sum += sorted_seq[i];

    }



    return min_sum;

}



int main() {

    int t;

    cin >> t;

    

    while (t-- > 0) {

        int n, l, r;

        cin >> n >> l >> r;

        vector<int> sequence(n);

        

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

            cin >> sequence[i];

        }

        

        cout << solve(n, sequence, l, r) << endl;

    }



    return 0;

}



//#include <iostream>

//#include <vector>

//#include <algorithm>

//

//using namespace std;

//int solve(int n, vector<int>& sequence, int l, int r) {

//    vector<int> left_part(sequence.begin(), sequence.begin() + r);

//    vector<int> right_part(sequence.begin() + (l - 1), sequence.end());

//    sort(left_part.begin(), left_part.end(), greater<int>());

//    sort(right_part.begin(), right_part.end()); // Ascending

//

//    int left_sum = 0, right_sum = 0;

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

//        left_sum += left_part[i];

//        right_sum += right_part[i - (l - 1)];

//    }

//

//    return min(left_sum, right_sum);

//}

//

//int main() {

//    int t;

//    cin >> t;

//    

//    while (t-- > 0) {

//        int n, l, r;

//        cin >> n >> l >> r;

//        vector<int> sequence(n);

//        

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

//            cin >> sequence[i];

//        }

//        

//        cout << solve(n, sequence, l, r) << endl;

//    }

//

//    return 0;

//}



Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

// Function to solve the problem
long long solve(int n, vector<int> sequence, int l, int r) {
    vector<int> copy = sequence;
    
    // Sorting first 'r' elements in descending order
    sort(copy.begin(), copy.begin() + r, greater<int>());
    
    // Sorting from 'l' to 'n' in ascending order
    sort(sequence.begin() + (l - 1), sequence.end());
    
    long long left = 0, right = 0; // Use long long to store large sums
    
    for (int i = l - 1; i < r; i++) {
        left += copy[i];
        right += sequence[i];
    }
    
    return min(left, right);
}

int main() {
    int t;
    cin >> t;
    
    while (t-- > 0) {
        int n, l, r;
        cin >> n >> l >> r;
        vector<int> sequence(n);
        
        for (int i = 0; i < n; i++) {
            cin >> sequence[i];
        }
        
        cout << solve(n, sequence, l, r) << endl;
    }

    return 0;
}

//#include <iostream>
//#include <vector>
//#include <algorithm>
//
//using namespace std;
//int solve(int n, vector<int>& sequence, int l, int r) {
//    vector<int> left_part(sequence.begin(), sequence.begin() + r);
//    vector<int> right_part(sequence.begin() + (l - 1), sequence.end());
//    sort(left_part.begin(), left_part.end(), greater<int>());
//    sort(right_part.begin(), right_part.end()); // Ascending
//
//    int left_sum = 0, right_sum = 0;
//    for (int i = l - 1; i < r; i++) {
//        left_sum += left_part[i];
//        right_sum += right_part[i - (l - 1)];
//    }
//
//    return min(left_sum, right_sum);
//}
//
//int main() {
//    int t;
//    cin >> t;
//    
//    while (t-- > 0) {
//        int n, l, r;
//        cin >> n >> l >> r;
//        vector<int> sequence(n);
//        
//        for (int i = 0; i < n; i++) {
//            cin >> sequence[i];
//        }
//        
//        cout << solve(n, sequence, l, r) << endl;
//    }
//
//    return 0;
//}