ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

using namespace std;



void solve() {

    int n, l, r;

    cin >> n >> l >> r;



    vector<int> arr(n);

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

        cin >> arr[i];

    }



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



    int sum = 0;

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

        sum += arr[i];

    }

    cout << sum << "\n";

}    



int main() {

ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}



Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    
    // אפשרות 1: לקחת מההתחלה עד r
    vector<int> prefix(arr.begin(), arr.begin() + r);
    sort(prefix.begin(), prefix.end());
    int sum1 = 0;
    for (int i = 0; i < (r - l + 1); ++i) {
        sum1 += prefix[i];
    }
    
    // אפשרות 2: לקחת מ-l-1 עד הסוף
    vector<int> suffix(arr.begin() + l - 1, arr.end());
    sort(suffix.begin(), suffix.end());
    int sum2 = 0;
    for (int i = 0; i < (r - l + 1); ++i) {
        sum2 += suffix[i];
    }
    
    cout << min(sum1, sum2) << "\n";
}    

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    
    // אפשרות 1: לקחת מההתחלה עד r
    vector<int> prefix(arr.begin(), arr.begin() + r);
    sort(prefix.begin(), prefix.end());
    int sum1 = 0;
    for (int i = 0; i < (r - l + 1); ++i) {
        sum1 += prefix[i];
    }
    
    // אפשרות 2: לקחת מ-l-1 עד הסוף
    vector<int> suffix(arr.begin() + l - 1, arr.end());
    sort(suffix.begin(), suffix.end());
    int sum2 = 0;
    for (int i = 0; i < (r - l + 1); ++i) {
        sum2 += suffix[i];
    }
    
    cout << min(sum1, sum2) << "\n";
}    

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

using namespace std;



void solve() {

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> arr(n);

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

        cin >> arr[i];

    }

    

    vector<int> prefix(arr.begin(), arr.begin() + r);

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

    long long sum1 = 0;

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

        sum1 += prefix[i];

    }

    

    vector<int> suffix(arr.begin() + l - 1, arr.end());

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

    long long sum2 = 0;

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

        sum2 += suffix[i];

    }

    

    cout << min(sum1, sum2) << "\n";

}



int main() {

ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

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


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

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

    vector<int> arr(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }

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

    int sum = 0;
    for (int i = 1; i <= (r - l + 1); ++i) {
        sum += arr[i];
    }
    cout << sum << "\n";
}    

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

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

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

    vector<int> arr(n+1);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

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

    int sum = 0;
    for (int i = 0; i <= (r - l + 1); ++i) {
        sum += arr[i];
    }
    cout << sum << "\n";
}    

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

using namespace std;



void solve() {

    int n, l, r;

    cin >> n >> l >> r;



    vector<int> arr(n);

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

        cin >> arr[i];

    }



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



    int sum = 0;

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

        sum += arr[i];

    }

    cout << sum << "\n";

}    



int main() {

ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

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

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

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

    vector<int> arr(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i];
    }

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

    int sum = 0;
    for (int i = 1; i <= (r - l + 1); ++i) {
        sum += arr[i];
    }
    cout << sum << "\n";
}    

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


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

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

    vector<int> arr(n+1);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }

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

    int sum = 0;
    for (int i = 0; i <= (r - l + 1); ++i) {
        sum += arr[i];
    }
    cout << sum << "\n";
}    

int main() {
ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

#include<vector>

#include<string>

using namespace std;



int main(){

    int t; cin >> t;



    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

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

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                answer = "NO"; break;

            }

        }



        cout << answer << "\n";





    }

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#include<vector>

#include<string>

using namespace std;



int main(){

    int t; cin >> t;



    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

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

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                arr[i-1] = abs(arr[i-1] - arr[i-2]);

                answer = "NO"; break;

            }

        }



        cout << answer << "\n";





    }

}

Submission (verdict: Accepted):
#include<iostream>

#include<vector>

#include<string>

using namespace std;



int main(){

    int t; cin >> t;



    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

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

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                answer = "NO"; break;

            } else arr[i-1] = abs(arr[i-1] - arr[i-2]);

        }



        cout << answer << "\n";





    }

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

#include<vector>

#include<string>

using namespace std;



int main(){

    int t; cin >> t;



    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

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

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                answer = "NO"; break;

            }

        }



        cout << answer << "\n";





    }

}

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

#include<vector>

#include<string>

using namespace std;



int main(){

    int t; cin >> t;



    while(t--){

        int n; cin >> n;

        int arr[n+1]; arr[0]=0;

        string answer = "YES";

        for(int i = 1; i <= n; i++) cin >> arr[i];

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

            if(arr[i] < abs(arr[i-1] - arr[i-2])) {

                arr[i-1] = abs(arr[i-1] - arr[i-2]);

                answer = "NO"; break;

            }

        }



        cout << answer << "\n";





    }

}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Memory limit exceeded on test 4):
#include <bits/stdc++.h>
    #include <ctime>
    #include <chrono>
    #include <cmath>
    using namespace std;
    typedef long long ll; 
    typedef vector<int> vi;
    typedef vector<ll> vll;
    #define cy() cout << "YES" << '\n'
    #define cn() cout << "NO" << '\n'
    const double pi=    3.14159265358979323846;
 
    // Function to check if an integer is prime or not
    bool isprime(ll n){
        if(n<2){
            return false;
        }
        for(ll i = 2;i<=sqrt(n);i++){
            if(n%i==0){
                return false;
            } 
        }
        return true;
    }
    bool pointscompare(pair<string,int> &a ,pair<string,int>  &b){
        return a.second>b.second;
    }
    bool goaldiffcompare(pair<string,int> &a , pair<string,int> &b){
        return a.second>b.second;
    }
    bool cmp(pair<string, int>& a, 
        pair<string, int>& b) 
    { 
        return a.second < b.second; 
    }
    bool isSorted(const std::vector<int>& arr) {
    for (size_t i = 1; i < arr.size(); ++i) {
        if (arr[i] < arr[i - 1]) {
            return false; 
        }
        }
        return true; 
    }
   
    void solve(){   
        //     ...............................
        //     >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        string s;
        cin >> s;
        int sum = 0;
        int two = 0;
        int three = 0;

        for(int i = 0;i<s.size();i++){
            sum += s[i] - '0';
            if(s[i]=='2'){
                two+=1;
            }
            if(s[i]=='3'){
                three+=1;
            }
        }
        map<pair<int,int>,int> v;
        for(int i = 0;i<=two;i++){
            for(int j = 0;j<=three;j++){
                v[{i,j}] = 2*i + 6*j;
            }
        }
        for(auto x : v){
            // cout << x.first.first << " " << x.first.second << " " << x.second << ' ' << sum%9 << '\n';
        }
        bool p =  false;
        for(auto x : v){
            if((sum+x.second)%9==0){
                cout << "YES" << '\n';
                p = true;
                break;
            }
        }
        if(!p){
            cout << "NO" << '\n';
        }
        
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        std::cout.tie(0); 
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
        int tt;
        cin >> tt;
        while(tt--){
            using std::chrono::high_resolution_clock;
            using std::chrono::duration_cast;
            using std::chrono::duration;
            using std::chrono::milliseconds;
            auto t1 = high_resolution_clock::now();
           solve();
            auto t2 = high_resolution_clock::now();
            auto ms_int = duration_cast<milliseconds>(t2 - t1);
            duration<double, std::milli> ms_double = t2 - t1;
            // std::cout << ms_double.count() << "ms\n";
        }
        return 0;  
    }
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
   

    while (t--){
		int n;
		cin >> n;
        vector<int>a(n+1);
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl; 
    }
    return 0;
}


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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
   

    while (t--){
		int n;
		cin >> n;
        vector<ll>a(n+1);
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl; 
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        
        rr(i, n)
        {
            cin >> a[i];
        }

        int maxi = accumulate(all(a), 0);
        
        while (a.size() > 1)
        {
            reverse(all(a)); 

            vector<int> arr;
            for (int i = 0; i < (int)a.size() - 1; i++)
            {
                arr.pb(a[i + 1] - a[i]);
            }

            a = arr; 
            maxi = max(maxi, accumulate(all(a), 0)); 
        }

        cout << maxi << endl;
    }

    return 0;
}


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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<ll> a(n); 
        
        rr(i, n)
        {
            cin >> a[i];
        }

        ll maxi = accumulate(all(a), 0LL); 
        
        while (a.size() > 1)
        {
            reverse(all(a)); 

            vector<ll> arr;
            for (int i = 0; i < (int)a.size() - 1; i++)
            {
                arr.pb(a[i + 1] - a[i]);
            }

            a = arr; 
            maxi = max(maxi, accumulate(all(a), 0LL));
        }

        cout << maxi << endl;
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<ll> a(n); 
        
        rr(i, n)
        {
            cin >> a[i];
        }

        ll maxi = accumulate(all(a), 0LL); 
        
        while (a.size() > 1)
        {
            reverse(all(a)); 

            vector<ll> arr;
            for (int i = 0; i < (int)a.size() - 1; i++)
            {
                arr.pb(a[i + 1] - a[i]);
            }

            a = arr; 
            maxi = max(maxi, accumulate(all(a), 0LL));
        }

        cout << maxi << endl;
    }

    return 0;
}


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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
   

    while (t--){
		int n;
		cin >> n;
        vector<int>a(n+1);
		for (int i = 1; i <= n; i++) cin >> a[i];
		int now = n;
		long long ans = -1e18;
		for (int i = 1; i <= n; i++){
			long long sum = 0;
			for (int i = 1; i <= now; i++) sum = (sum + a[i]) ;
			if (i == 1) ans = max(ans, sum);
			else ans = max(ans, max(sum, ( - sum) ));
			for (int i = 1; i < now; i++) a[i] = (a[i + 1] - a[i]) ;
			now--;
		}
		cout << ans << endl; 
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);
        
        rr(i, n)
        {
            cin >> a[i];
        }

        int maxi = accumulate(all(a), 0);
        
        while (a.size() > 1)
        {
            reverse(all(a)); 

            vector<int> arr;
            for (int i = 0; i < (int)a.size() - 1; i++)
            {
                arr.pb(a[i + 1] - a[i]);
            }

            a = arr; 
            maxi = max(maxi, accumulate(all(a), 0)); 
        }

        cout << maxi << endl;
    }

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


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

using namespace std;



#define ll long long

#define mod 1000000007

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

#define pb push_back

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

#define nn '\n'



// Fast Input-Output

void fastIO()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

}



int main()

{

    fastIO();



    int t;

    cin >> t;

    while (t--)

    {

        int n, l, r;

        cin >> n >> l >> r;

        vector<int> a(n);

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

        {

            cin >> a[i];

        }



        vector<int> before, after, btw;

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

        {

            if (i < l - 1)

                before.pb(a[i]);

            else if (i > r - 1)

                after.pb(a[i]);

            else

                btw.pb(a[i]);

        }



        sort(all(before));

        sort(all(after));

        sort(all(btw));



        int sum = accumulate(all(btw), 0);

        int mini = sum;



        int i = 0, j = btw.size() - 1;

        while (i < before.size() && j >= 0 && before[i] < btw[j])

        {

            sum = sum - btw[j] + before[i];

            mini = min(mini, sum);

            i++;

            j--;

        }



        sum = accumulate(all(btw), 0);



        i = 0, j = btw.size() - 1;

        while (i < after.size() && j >= 0 && after[i] < btw[j])

        {

            sum = sum - btw[j] + after[i];

            mini = min(mini, sum);

            i++;

            j--;

        }



        cout << mini << nn;

    }



    return 0;

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

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

#define ll long long
#define mod 1000000007
#define rr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        ll n, l, r;
        cin >> n >> l >> r;
        vector<ll> a(n);
        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        vector<ll> before, after, btw;
        for (ll i = 0; i < n; i++)
        {
            if (i < l - 1)
                before.pb(a[i]);
            else if (i > r - 1)
                after.pb(a[i]);
            else
                btw.pb(a[i]);
        }

        sort(all(before));
        sort(all(after));
        sort(all(btw));

        ll sum = accumulate(all(btw), 0);
        ll mini = sum;

        ll i = 0, j = btw.size() - 1;
        while (i < before.size() && j >= 0 && before[i] < btw[j])
        {
            sum = sum - btw[j] + before[i];
            mini = min(mini, sum);
            i++;
            j--;
        }

        sum = accumulate(all(btw), 0);

        i = 0, j = btw.size() - 1;
        while (i < after.size() && j >= 0 && after[i] < btw[j])
        {
            sum = sum - btw[j] + after[i];
            mini = min(mini, sum);
            i++;
            j--;
        }

        cout << mini << nn;
    }

    return 0;
}


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

#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define nn '\n'

// Fast Input-Output
void fastIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastIO();

    int t;
    cin >> t;
    while (t--)
    {
        int n, l, r;
        cin >> n >> l >> r;
        l--; // Adjust for 0-based index

        vector<ll> arr(n);
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }

        vector<ll> brr = arr;
        sort(brr.begin() + l, brr.end());

        vector<ll> crr = arr;
        sort(crr.begin(), crr.begin() + r, greater<ll>());

        ll sum_brr = accumulate(brr.begin() + l, brr.begin() + r, 0LL);
        ll sum_crr = accumulate(crr.begin() + l, crr.begin() + r, 0LL);

        cout << min(sum_brr, sum_crr) << nn;
    }

    return 0;
}