ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> mp;
        for(int i=0;i<n;i++){
            int a;
            cin>>a;
            mp[a]++;
        }
        vector<int> b(m);
        priority_queue<int> pq;
        for(int i=0;i<m;i++){
            cin>>b[i];
            pq.push(b[i]);
        } 
        
        int opp = n-m;
        while(opp>=0 && !pq.empty()){
            auto tp = pq.top();
            pq.pop();
            if(mp[tp] > 0){
                mp[tp]--;
            }else{
                pq.push(tp/2);
                opp--;
                if(tp%2 == 0){
                    pq.push(tp/2);
                }else{
                    pq.push((tp/2) + 1);
                }
            }
        }
        
        if(!pq.empty() || opp>0){
            cout<<"No\n";
        }else{
            cout<<"Yes\n";
        }
    }

    return 0;
}

Submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;

bool canTransform(vector<int>& a, vector<int>& b) {
    // Count the frequency of each number in a and b
    map<int, int> freqA, freqB;
    for (int num : a) freqA[num]++;
    for (int num : b) freqB[num]++;
    
    // Iterate through the numbers in a
    for (auto& [num, count] : freqA) {
        if (freqB.count(num)) {
            // If the number exists in b, reduce the count
            int minCount = min(count, freqB[num]);
            count -= minCount;
            freqB[num] -= minCount;
        }
        // If there are still numbers left in a, try to merge them
        if (count > 0) {
            if (freqB.count(num + 1)) {
                int minCount = min(count, freqB[num + 1]);
                count -= minCount;
                freqB[num + 1] -= minCount;
            }
        }
        // If there are still numbers left in a, it's impossible to match
        if (count > 0) return false;
    }
    
    // Check if all numbers in b are matched
    for (auto& [num, count] : freqB) {
        if (count > 0) return false;
    }
    
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        vector<int> a(n), b(m);
        for (int i = 0; i < n; ++i) cin >> a[i];
        for (int i = 0; i < m; ++i) cin >> b[i];
        
        if (canTransform(a, b)) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <bits/stdc++.h>
using namespace std;

bool canTransform(vector<int>& a, vector<int>& b) {
    // Count the frequency of each number in a and b
    map<int, int> freqA, freqB;
    for (int num : a) freqA[num]++;
    for (int num : b) freqB[num]++;
    
    // Iterate through the numbers in a
    for (auto& [num, count] : freqA) {
        if (freqB.count(num)) {
            // If the number exists in b, reduce the count
            int minCount = min(count, freqB[num]);
            count -= minCount;
            freqB[num] -= minCount;
        }
        // If there are still numbers left in a, try to merge them
        if (count > 0) {
            if (freqB.count(num + 1)) {
                int minCount = min(count, freqB[num + 1]);
                count -= minCount;
                freqB[num + 1] -= minCount;
            }
        }
        // If there are still numbers left in a, it's impossible to match
        if (count > 0) return false;
    }
    
    // Check if all numbers in b are matched
    for (auto& [num, count] : freqB) {
        if (count > 0) return false;
    }
    
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        vector<int> a(n), b(m);
        for (int i = 0; i < n; ++i) cin >> a[i];
        for (int i = 0; i < m; ++i) cin >> b[i];
        
        if (canTransform(a, b)) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    
    return 0;
}

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

// Function to solve each test case
void solve() {
    int n, m;
    cin >> n >> m;

    multiset<long long> a, b;

    for (int i = 0; i < n; i++) {
        long long x;
        cin >> x;
        a.insert(x);
    }

    for (int i = 0; i < m; i++) {
        long long x;
        cin >> x;
        b.insert(x);
    }

    while (!b.empty()) {
        auto max_b = *b.rbegin(); // Maximum element in b

        // Check if the largest element in b can be formed from elements in a
        auto it = a.find(max_b);
        if (it != a.end()) {
            a.erase(it); // Erase the element from a
            b.erase(--b.end()); // Erase the element from b
        } else {
            // If not possible, check if we can split max_b into smaller parts
            b.erase(--b.end());
            if (max_b == 1) {
                cout << "NO\n";
                return;
            }

            b.insert(max_b / 2);
            b.insert((max_b + 1) / 2);
        }
    }

    cout << "YES\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 1):
// Online C++ compiler to run C++ program online
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int,int> mp;
        for(int i=0;i<n;i++){
            int a;
            cin>>a;
            mp[a]++;
        }
        vector<int> b(m);
        priority_queue<int> pq;
        for(int i=0;i<m;i++){
            cin>>b[i];
            pq.push(b[i]);
        } 
        
        int opp = n-m;
        while(opp>=0 && !pq.empty()){
            auto tp = pq.top();
            pq.pop();
            if(mp[tp] > 0){
                mp[tp]--;
            }else{
                pq.push(tp/2);
                opp--;
                if(tp%2 == 0){
                    pq.push(tp/2);
                }else{
                    pq.push((tp/2) + 1);
                }
            }
        }
        
        if(!pq.empty() || opp>0){
            cout<<"No\n";
        }else{
            cout<<"Yes\n";
        }
    }

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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



using namespace std;

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

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

typedef long long ll;

typedef long double ld;

const ll mod = 1e9 + 7;

const ll MOD = 998244353;





int main() {



    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll tt;

    cin >> tt;

    while (tt--) {

        string st;

        cin >> st;

        vector < ll > s(st.size());

        for (ll i = 0; i < s.size(); i++) {

            s[i] = st[i] - '0';

        }

        for (ll i = 1; i < s.size(); i++) {

            for (ll j = i - 1; j >= min(0ll, i - 9ll); j--) {

                if (s[j+1]> s[j]+1) {

                    ll temp=s[j];

                    s[j]=s[j+1]-1;

                    s[j+1]=temp;

                }

                else break;

            }

        }



        ll ans = 0;

        for (ll i = 0; i < s.size(); i++) {

            ans += s[i];

            ans *= 10;

        }

        cout << ans/10 << endl;

    }





    return 0;

}

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



using namespace std;

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

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

typedef long long ll;

typedef long double ld;

const ll mod = 1e9 + 7;

const ll MOD = 998244353;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll tt;

    cin >> tt;

    while (tt--) {

        string st;

        cin >> st;

        vector<ll> s(st.size());

        

        // Convert string to vector of digits

        for (ll i = 0; i < s.size(); i++) {

            s[i] = st[i] - '0';

        }



        // Iterate over each element of the array and apply the transformation rules

        for (ll i = 1; i < s.size(); i++) {

            // We need to make sure we are within valid bounds for j

            for (ll j = i - 1; j >= max(0ll, i - 9ll); j--) {

                // Ensure the current swap is valid by checking bounds

                if (s[j+1] > s[j] + 1) {

                    ll temp = s[j];

                    s[j] = s[j+1] - 1;

                    s[j+1] = temp;

                }

                else {

                    break; // Stop if no valid swap can be made

                }

            }

        }



        // Calculate the final number based on the transformed array s

        ll ans = 0;

        for (ll i = 0; i < s.size(); i++) {

            ans = ans * 10 + s[i];

        }

        

        cout << ans << endl;

    }



    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)

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



using namespace std;

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

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

typedef long long ll;

typedef long double ld;

const ll mod = 1e9 + 7;

const ll MOD = 998244353;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll tt;

    cin >> tt;

    while (tt--) {

        string st;

        cin >> st;

        vector<ll> s(st.size());

        

        // Convert string to vector of digits

        for (ll i = 0; i < s.size(); i++) {

            s[i] = st[i] - '0';

        }



        // Iterate over each element of the array and apply the transformation rules

        for (ll i = 1; i < s.size(); i++) {

            // We need to make sure we are within valid bounds for j

            for (ll j = i - 1; j >= max(0ll, i - 9ll); j--) {

                // Ensure the current swap is valid by checking bounds

                if (s[j+1] > s[j] + 1) {

                    ll temp = s[j];

                    s[j] = s[j+1] - 1;

                    s[j+1] = temp;

                }

                else {

                    break; // Stop if no valid swap can be made

                }

            }

        }



        // Calculate the final number based on the transformed array s

        ll ans = 0;

        for (ll i = 0; i < s.size(); i++) {

            ans = ans * 10 + s[i];

        }

        

        cout << ans << endl;

    }



    return 0;

}



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



using namespace std;

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

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

typedef long long ll;

typedef long double ld;

const ll mod = 1e9 + 7;

const ll MOD = 998244353;



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll tt;

    cin >> tt;

    while (tt--) {

        string st;

        cin >> st;

        vector<ll> s(st.size());

        

        // Convert string to vector of digits

        for (ll i = 0; i < s.size(); i++) {

            s[i] = st[i] - '0';

        }



        // Iterate over each element of the array and apply the transformation rules

        for (ll i = 1; i < s.size(); i++) {

            // We need to make sure we are within valid bounds for j

            for (ll j = i - 1; j >= max(0ll, i - 9ll); j--) {

                // Ensure the current swap is valid by checking bounds

                if (s[j+1] > s[j] + 1) {

                    ll temp = s[j];

                    s[j] = s[j+1] - 1;

                    s[j+1] = temp;

                }

                else {

                    break; 

                }

            }

        }



        string ans="";

        for (ll i = 0; i < s.size(); i++) {

            ans+=s[i]+'0';

        }

        

        cout << ans << endl;

    }



    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


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



using namespace std;

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

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

typedef long long ll;

typedef long double ld;

const ll mod = 1e9 + 7;

const ll MOD = 998244353;





int main() {



    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    ll tt;

    cin >> tt;

    while (tt--) {

        string st;

        cin >> st;

        vector < ll > s(st.size());

        for (ll i = 0; i < s.size(); i++) {

            s[i] = st[i] - '0';

        }

        for (ll i = 1; i < s.size(); i++) {

            for (ll j = i - 1; j >= min(0ll, i - 9ll); j--) {

                if (s[j+1]> s[j]+1) {

                    ll temp=s[j];

                    s[j]=s[j+1]-1;

                    s[j+1]=temp;

                }

                else break;

            }

        }



        ll ans = 0;

        for (ll i = 0; i < s.size(); i++) {

            ans += s[i];

            ans *= 10;

        }

        cout << ans/10 << endl;

    }





    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef set<int> si;

typedef pair<int, int> pi;

typedef map<int, int> mi;

#define endl "\n"

#define nl cout << "\n"

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

#define yes cout << "YES" << endl;

#define no cout << "NO" << endl;

#define ANS cout<<ans<<"\n"

#define read(v) for(int i=0;i<(int)v.size();++i) cin>>v[i]

#define read1(v) for(int i=1;i<(int)v.size();++i) cin>>v[i]

#define print(v) {for(int i=0;i<(int)v.size();++i)cout<<v[i]<<" ";nl;}

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define bits(x) __builtin_popcountll(x)

#define minvec(a) *min_element(all(a))

#define maxvec(a) *max_element(all(a))

const ll mod = 1e9+7;

const ll mod1 = 998244353;

const ld pie = 3.141592653589793238;



void solve()

{

    int n;  cin>>n;

    vi a(n);    read(a);



    if(is_sorted(a.begin(), a.end())){

        yes return;

    }

    if(is_sorted(a.rbegin(), a.rend())){

        no return;

    }

    

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

        int dec= min(a[i], a[i+1]);

        a[i]-= dec;

        a[i+1]-= dec;



        if(is_sorted(a.begin(), a.end())){

            yes return;

        }

    }



    no

}



int main()

{

    int t; cin>>t; 

    while(t--){

        solve();

    }



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 8):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef set<int> si;

typedef pair<int, int> pi;

typedef map<int, int> mi;

#define endl "\n"

#define nl cout << "\n"

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

#define yes cout << "YES" << endl;

#define no cout << "NO" << endl;

#define ANS cout<<ans<<"\n"

#define read(v) for(int i=0;i<(int)v.size();++i) cin>>v[i]

#define read1(v) for(int i=1;i<(int)v.size();++i) cin>>v[i]

#define print(v) {for(int i=0;i<(int)v.size();++i)cout<<v[i]<<" ";nl;}

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define bits(x) __builtin_popcountll(x)

#define minvec(a) *min_element(all(a))

#define maxvec(a) *max_element(all(a))

const ll mod = 1e9+7;

const ll mod1 = 998244353;

const ld pie = 3.141592653589793238;



void solve()

{

    int n;  cin>>n;

    vi a(n);    read(a);



    if(is_sorted(a.begin(), a.end())){

        yes return;

    }

    if(is_sorted(a.rbegin(), a.rend())){

        no return;

    }

    

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

        int dec= min(a[i], a[i+1]);

        a[i]-= dec;

        a[i+1]-= dec;



        if(is_sorted(a.begin(), a.end())){

            yes return;

        }

    }



    no

}



int main()

{

    int t; cin>>t; 

    while(t--){

        solve();

    }



    return 0;

}

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

using namespace std;

typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef set<int> si;

typedef pair<int, int> pi;

typedef map<int, int> mi;

#define endl "\n"

#define nl cout << "\n"

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

#define yes cout << "YES" << endl;

#define no cout << "NO" << endl;

#define ANS cout<<ans<<"\n"

#define read(v) for(int i=0;i<(int)v.size();++i) cin>>v[i]

#define read1(v) for(int i=1;i<(int)v.size();++i) cin>>v[i]

#define print(v) {for(int i=0;i<(int)v.size();++i)cout<<v[i]<<" ";nl;}

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define bits(x) __builtin_popcountll(x)

#define minvec(a) *min_element(all(a))

#define maxvec(a) *max_element(all(a))

const ll mod = 1e9+7;

const ll mod1 = 998244353;

const ld pie = 3.141592653589793238;



void solve()

{

    int n;  cin>>n;

    vi a(n);    read(a);



    if(is_sorted(a.begin(), a.end())){

        yes return;

    }

    if(is_sorted(a.rbegin(), a.rend())){

        no return;

    }

    

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

        int dec= min(a[i], a[i+1]);

        a[i]-= dec;

        a[i+1]-= dec;

    }



    if(is_sorted(a.begin(), a.end()))

        yes

    else

        no

}



int main()

{

    int t; cin>>t; 

    while(t--){

        solve();

    }



    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

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

using namespace std;

typedef long long ll;

typedef long double ld;

typedef vector<int> vi;

typedef set<int> si;

typedef pair<int, int> pi;

typedef map<int, int> mi;

#define endl "\n"

#define nl cout << "\n"

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

#define yes cout << "YES" << endl;

#define no cout << "NO" << endl;

#define ANS cout<<ans<<"\n"

#define read(v) for(int i=0;i<(int)v.size();++i) cin>>v[i]

#define read1(v) for(int i=1;i<(int)v.size();++i) cin>>v[i]

#define print(v) {for(int i=0;i<(int)v.size();++i)cout<<v[i]<<" ";nl;}

#define F first

#define S second

#define PB push_back

#define MP make_pair

#define bits(x) __builtin_popcountll(x)

#define minvec(a) *min_element(all(a))

#define maxvec(a) *max_element(all(a))

const ll mod = 1e9+7;

const ll mod1 = 998244353;

const ld pie = 3.141592653589793238;



void solve()

{

    int n;  cin>>n;

    vector<ll> a(n);    read(a);



    if(is_sorted(a.begin(), a.end())){

        yes return;

    }

    if(is_sorted(a.rbegin(), a.rend())){

        no return;

    }

    

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

        ll dec= min(a[i], a[i+1]);

        a[i]-= dec;

        a[i+1]-= dec;

    }



    if(is_sorted(a.begin(), a.end()))

        yes

    else

        no

}



int main()

{

    int t; cin>>t; 

    while(t--){

        solve();

    }



    return 0;

}

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

#include <vector>

using namespace std;

 

typedef long long ll;

 

void solve(){

    int n;

    cin >> n;

    vector<ll> a(n);

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

        cin >> a[i];

    }

    

    // For a non-decreasing sequence, we need to be able to zero-out all but the last element.

    // The very first operation is only possible if a[0] <= a[1].

    if(a[0] > a[1]){

        cout << "NO\n";

        return;

    }

    

    // Let d be the residual after zeroing-out a[0] using (a[0], a[1]).

    ll d = a[1] - a[0];

    

    // Process the rest of the array.

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

        if(a[i] < d){

            cout << "NO\n";

            return;

        }

        d = a[i] - d;

    }

    

    cout << "YES\n";

}

 

int main(){

    ios::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 1):
#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N=1e5+10;

int n,l,r;

int cnt1,cnt2;

int a[N],b[N];

void solve(){

    cin>>n>>l>>r;

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

        cin>>a[i];

        b[i]=a[i];

    }

    sort(a,a+r);

    sort(b+l-1,b+n);

    cnt1=0;cnt2=0;

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

        cnt1+=a[i];

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

        cnt2+=b[i];

    cout<<min(cnt1,cnt2)<<"\n";

}

signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

    int T;

    cin>>T;

    while(T--) solve();

    return 0;

}

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

#define int long long

using namespace std;

const int N=1e5+10;

int n,l,r;

int cnt1,cnt2;

int a[N],b[N];

void solve(){

    cin>>n>>l>>r;

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

        cin>>a[i];

        b[i]=a[i];

    }

    sort(a,a+r);

    sort(b+l-1,b+n);

    cnt1=0;cnt2=0;

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

        cnt1+=a[i];

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

        cnt2+=b[i];

    cout<<min(cnt1,cnt2)<<"\n";

}

signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

    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>
#define int long long
using namespace std;
const int N=1e5+10;
int n,l,r;
int cnt1,cnt2;
int a[N],b[N];
void solve(){
    cin>>n>>l>>r;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a+1,a+r+1);
    sort(b+l-1,b+n+1);
    cnt1=0;cnt2=0;
    for(int i=1;i<=r-l+1;i++)
        cnt1+=a[i];
    for(int i=l;i<=(l-1)+(r-l+1);i++)
        cnt2+=b[i];
    cout<<min(cnt1,cnt2)<<"\n";
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    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>
#define int long long
using namespace std;
const int N=1e5+10;
int n,l,r;
int cnt1,cnt2;
int a[N],b[N];
void solve(){
    cin>>n>>l>>r;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a+1,a+r+1);
    sort(b+l-1,b+n+1);
    cnt1=0;cnt2=0;
    for(int i=1;i<=r-l+1;i++)
        cnt1+=a[i];
    for(int i=l;i<=(l-1)+(r-l+1);i++)
        cnt2+=b[i];
    cout<<min(cnt1,cnt2)<<"\n";
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T;
    cin>>T;
    while(T--) solve();
    return 0;
}

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

#define int long long

using namespace std;

const int N=1e5+10;

int n,l,r;

int cnt1,cnt2;

int a[N],b[N];

void solve(){

    cin>>n>>l>>r;

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

        cin>>a[i];

        b[i]=a[i];

    }

    sort(a,a+r);

    sort(b+l-1,b+n);

    cnt1=0;cnt2=0;

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

        cnt1+=a[i];

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

        cnt2+=b[i];

    cout<<min(cnt1,cnt2)<<"\n";

}

signed main(){

    ios::sync_with_stdio(0);

    cin.tie(0);cout.tie(0);

    int T;

    cin>>T;

    while(T--) solve();

    return 0;

}