ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=(s[i]-'0');
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        if(sum%9==0)cout<<"yes"<<endl;
        else{
           int ans=9-(sum%9);
           bool flag=false;
            if(ans%2==0){
               for(int i=0;i<=cnt3;i++){
                long long temp=0;
                for(int j=0;j<=cnt2;j++){
                    temp+=(j*2)+(i*6);
                    if(temp==ans){
                        flag=true;
                        break;
                    }
                }
                if(flag==true)break;
               }
               if(flag==true)cout<<"YES"<<endl;
               else cout<<"NO"<<endl;
            }
            else{
                ans+=9;
                for(int i=0;i<=cnt3;i++){
                long long temp=0;
                for(int j=0;j<=cnt2;j++){
                    temp+=(j*2)+(i*6);
                }
                if(temp==ans)flag=true;
               }
               if(flag==true)cout<<"YES"<<endl;
               else cout<<"NO"<<endl;
            }
        }
        }
        
    }


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=s[i]-('0');
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        //cout<<sum<<endl;
        if(sum%9==0)cout<<"yes"<<endl;
        
        else{
            bool flag=false;
          for(int i=1;i<=2;i++){
            int ans=0;
            if(i==1)ans=9-(sum%9);
            else{
                ans=18-sum%9;
            }
            for(int t=0;2*t<=ans&&t<=cnt2;t++){
                int targetleft=ans-2*t;
                int three=targetleft/6;
                if(targetleft%6==0&&three<=cnt3)flag=true;
                if(flag==true)break;
            }
            if(flag==true)break;
          }
          if(flag)cout<<"yes"<<endl;
          else cout<<"no"<<endl;
        }
        }
        
    }
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=s[i]-'0';
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        if(sum%9==0)cout<<"YES"<<endl;
       else{ 
        int ans=9-(sum%9);
        //cout<<ans<<endl;
        //cout<<sum<<endl;
        if(ans%2==0){
            if(ans<6){
                if(cnt2>=ans/2)cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
            else{
                int a=ans/6;
                int b=ans%6;
                if(cnt3==0){
                    if(cnt2>=(ans/2))cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else if(cnt3==1){
                    if(cnt2>=(ans-6)/2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else{
                    if(cnt2>=(ans-12)/2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
            }
        }
        else{
                ans+=9;
                if(cnt2>=ans/2)cout<<"YES"<<endl;
              else{
                   int a=ans/6;
                   int b=ans%6;
                if(cnt3==0){
                    if(cnt2>=(ans/2))cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else if(cnt3==1){
                    if(cnt2>=(ans-6)/2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else{
                    if(cnt2>=(ans-12)/2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                }
        }
        }
    }
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=s[i]-'0';
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        if(sum%9==0)cout<<"YES"<<endl;
        else{
           int ans=9-(sum%9);
            if(ans%2==0){
                if(cnt2>=ans/2)cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3==1)&&cnt2>=(ans-6)/2))cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3>=2)&&cnt2>=(ans-12)/2))cout<<"yes"<<endl;
                else cout<<"no"<<endl;
            }
            else{
                ans+=9;
                 if(cnt2>=ans/2)cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3==1)&&cnt2>=(ans-6)/2))cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3>=2)&&cnt2>=(ans-12)/2))cout<<"yes"<<endl;
                else cout<<"no"<<endl;
            }
        }
        }
        
    }
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=s[i]-'0';
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        if(sum%9==0)cout<<"YES"<<endl;
       else{ 
        int ans=9-(sum%9);
        //cout<<ans<<endl;
        //cout<<sum<<endl;
        if(ans%2==0){
            if(ans<6){
                if(cnt2>=ans/2)cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
            else{
                int a=ans/6;
                int b=ans%6;
                if(cnt3==0){
                    if(cnt2>=(ans/2))cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else if(cnt3==1){
                    if(cnt2>=(ans-6)/2&&a>=1)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else{
                    if(cnt2>=(ans-12)/2&&a>=2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
            }
        }
        else{
                ans+=9;
                if(cnt2>=ans/2)cout<<"YES"<<endl;
              else{
                   int a=ans/6;
                   int b=ans%6;
                if(cnt3==0){
                    if(cnt2>=(ans/2))cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else if(cnt3==1){
                    if(cnt2>=(ans-6)/2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                else{
                    if(cnt2>=(ans-12)/2)cout<<"YES"<<endl;
                    else cout<<"NO"<<endl;
                }
                }
        }
        }
    }
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=s[i]-'0';
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        if(sum%9==0)cout<<"YES"<<endl;
        else{
           int ans=9-(sum%9);
            if(ans%2==0){
                if(cnt2>=ans/2)cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3==1)&&cnt2>=(ans-6)/2))cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3>=2)&&cnt2>=(ans-12)/2))cout<<"yes"<<endl;
                else cout<<"no"<<endl;
            }
            else{
                ans+=9;
                 if(cnt2>=ans/2)cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3==1)&&cnt2>=(ans-6)/2))cout<<"yes"<<endl;
                else if(ans/6>0&&((cnt3>=2)&&cnt2>=(ans-12)/2))cout<<"yes"<<endl;
                else cout<<"no"<<endl;
            }
        }
        }
        
    }


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        long long sum=0;
        long long cnt2=0;
        long long cnt3=0;
        for(int i=0;i<s.length();i++){
            sum+=(s[i]-'0');
            if(s[i]=='2')cnt2++;
            if(s[i]=='3')cnt3++;
        }
        if(sum%9==0)cout<<"yes"<<endl;
        else{
           int ans=9-(sum%9);
           bool flag=false;
            if(ans%2==0){
               for(int i=0;i<=cnt3;i++){
                long long temp=0;
                for(int j=0;j<=cnt2;j++){
                    temp+=(j*2)+(i*6);
                    if(temp==ans){
                        flag=true;
                        break;
                    }
                }
                if(flag==true)break;
               }
               if(flag==true)cout<<"YES"<<endl;
               else cout<<"NO"<<endl;
            }
            else{
                ans+=9;
                for(int i=0;i<=cnt3;i++){
                long long temp=0;
                for(int j=0;j<=cnt2;j++){
                    temp+=(j*2)+(i*6);
                }
                if(temp==ans)flag=true;
               }
               if(flag==true)cout<<"YES"<<endl;
               else cout<<"NO"<<endl;
            }
        }
        }
        
    }
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
       int temp ; 
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }
       
       vector<int>v;
       for(auto &it : mp)
       v.push_back(it.second);
       sort(begin(v),end(v));
       int ans = v.size();
       
       for(int i = 0 ; i<n ; i++)
       {
           k-=v[i];
           if(k<=0)
           break;
           
           ans--;
          
       }
       cout<<max(ans,1)<<endl;
       
       
        
    }
    
    

    
    
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
       int temp ; 
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }
       
       vector<int>v;
       for(auto it : mp)
       v.push_back(it.second);
       sort(v.begin(),v.end());
       int ans = v.size();
       
       for(int i = 0 ; i<v.size() ; i++)
       {
           k-=v[i];
           if(k<=0)
           break;
           
           ans--;
          
       }
       cout<<max(ans,1)<<endl;
       
       
        
    }
    
    
return 0;
    
    
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
        vector<int>arr(n);
        for(int i =0 ; i< n ;i++)
        {
            cin>>arr[i];
        }
        sort(arr.begin(),arr.end());
        
        // min element nikalo
        int mini =INT_MAX;
        for(int &i : arr)
        {
            mini = min(mini,i);
            
        }
        int count =0;
        
      if(k ==0 )
      {
          set<int>st;
          for(int &it : arr)
          {
              st.insert(it);
              
          }
          return st.size();
      }
      else{
         
          
              for(int i =0 ; i<n ; i++)
              {
                  if(arr[i]>mini)
                  {
                      arr[i] = mini;
                      k--;
                      count++;
                  }
                  if(k==0)break;
              }
          
      }
      return count;
        
        
        
        
    }
    
    
    
    
    
    
    
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
       int temp ; 
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }
       
       vector<int>v;
       for(auto &it : mp)
       v.push_back(it.second);
       sort(begin(v),end(v));
       int ans = v.size();
       
       for(int i = 0 ; i<n ; i++)
       {
           k-=v[i];
           if(k<=0)
           break;
           
           ans--;
          
       }
       cout<<max(ans,1)<<endl;
       
       
        
    }
    
    

    
    
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Runtime error on test 1):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
        vector<int>arr(n);
        for(int i =0 ; i< n ;i++)
        {
            cin>>arr[i];
        }
        sort(arr.begin(),arr.end());
        
        // min element nikalo
        int mini =INT_MAX;
        for(int &i : arr)
        {
            mini = min(mini,i);
            
        }
        int count =0;
        
      if(k ==0 )
      {
          set<int>st;
          for(int &it : arr)
          {
              st.insert(it);
              
          }
          return st.size();
      }
      else{
         
          
              for(int i =0 ; i<n ; i++)
              {
                  if(arr[i]>mini)
                  {
                      arr[i] = mini;
                      k--;
                      count++;
                  }
                  if(k==0)break;
              }
          
      }
      return count;
        
        
        
        
    }
    
    
    
    
    
    
    
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
       int temp ; 
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }
       
       vector<int>v;
       for(auto it : mp)
       v.push_back(it.second);
       sort(v.begin(),v.end());
       int ans = v.size();
       
       for(int i = 0 ; i<v.size() ; i++)
       {
           k-=v[i];
           if(k<=0)
           break;
           
           ans--;
          
       }
       cout<<max(ans,1)<<endl;
       
       
        
    }
    
    
return 0;
    
    
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main(){
    
    int t ;
    cin>>t;
    while(t--)
    {
        int n ,k;
        cin>>n>>k;
       int temp ; 
       map<int,int>mp;
       for(int i= 0 ; i<n ; i++)
       {
           cin>>temp;
           mp[temp]++;
       }
       
       vector<int>v;
       for(auto it : mp)
       v.push_back(it.second);
       sort(v.begin(),v.end());
       int ans = v.size();
       
       for(int i = 0 ; i<v.size() ; i++)
       {
           k-=v[i];
           if(k<0)
           break;
           
           ans--;
          
       }
       cout<<max(ans,1)<<endl;
       
       
        
    }
    
    
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;



#define ll        long long

#define ld        long duble

#define ull       unsigned ll

#define vi      vector<int>

#define vll       vector<ll>

#define vld       vector<ld>

#define vstr      vector<string>

#define vvi     vector<vector<int>>

#define vvll    vector<vector<ll>>

#define vvld    vector<vector<ld>>

#define pii       pair<int, int>

#define pll       pair<ll, ll>

#define mp        make_pair

#define pb        push_back

#define sz(x)     (int) x.size()

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

#define all_0(x)       memset(x,0,sizeof(x))

#define all_neg(x)     memset(x,-1,sizeof(x))

#define all_1(x)       memset(x,1,sizeof(x))

#define  bitcount(x)   (int)__builtin_popcount(x)

#define  Lsb(x)      (int)__builtin_ctzll(x)

#define fr0(i, p, n)     for(ll i = p; i < n; i++)

#define fr1(i, p, n)     for(ll i = p; i <=n; i++)

#define fast           ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

#define in(n)          long long n;   cin >> n

#define ins(s)         string s;   cin >> s

#define csp(x)         cout<<(x)<<" "

#define c1(x)          cout<<(x)<<endl

#define c2(x,y)        cout<<(x)<<" "<<(y)<<endl

#define c3(x,y,z)      cout<<(x)<<" "<<(y)<<" "<<(z)<<endl

#define c4(a,b,c,d)    cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl



#define YES            cout<<"YES"<<endl

#define Yes            cout<<"Yes"<<endl

#define NO             cout<<"NO"<<endl

#define No             cout<<"No"<<endl

#define nl             printf("\n")

#define ff             first

#define ss             second

#define endl           "\n"



const int mod = (int) 1e9 + 7;

const int inf = (int) 2e9 + 5;

const ll  Inf = (ll) 2e18 + 5;

const int N   = (int) 2e5 + 5;



int solve() {



  int n,l,r;

  cin>>n>>l>>r;

  int a[n+2];

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

  	cin>>a[i];

  }



  sort(a,a+n);

  int sum =0;

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

  	sum+=a[i];

  }

  cout<<sum<<endl;



  return 0;

}



int main() {

  fast;

  int test = 1;

  cin >> test;

  while (test--) {

    solve();

  }

  return 0;

}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

#define int long long

int recurrencia(string a, string b, string & c, int elem, int ans, bool nec, bool esa){
    if(elem >= c.size()){
        return ans;
    }
    if(nec == true){
        if(esa == true)
            a.pop_back();
        else
            b.pop_back();
        nec = false;
    }
    if(a.size() == 0 && b.size() == 0){
        return ans;
    }
    if(a.size() == 0){
        for(int j = b.size()-1; j>=0; j--){
            if(b[j] != c[elem])
                ans++;
            elem++;
        }
        return ans;
    }
    else if(b.size() == 0){
        for(int j = a.size()-1; j>=0; j--){
            if(a[j] != c[elem])
                ans++;
            elem++;
        }
        return ans;
    }
    else if(c[elem] != a[a.size()-1] && c[elem] != b[b.size()-1]){
        ans++;
        esa = true;
        nec = true;
        int res1 = recurrencia(a, b, c, elem+1, ans, nec, esa);
        esa = false;
        int res2 = recurrencia(a, b, c, elem+1, ans, nec, esa);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
        nec = false;
    }
    else if(c[elem] == a[a.size()-1] && c[elem] == b[b.size()-1]){
        esa = true;
        nec = true;
        int res1 = recurrencia(a, b, c, elem+1, ans, nec, esa);
        esa = false;
        int res2 = recurrencia(a, b, c, elem+1, ans, nec, esa);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
        nec = false;
    }
    else if(c[elem] == a[a.size()-1]){
        nec = true;
        esa = true;
        int res1 = recurrencia(a, b, c, elem+1, ans, nec, esa);
        esa = false;
        int res2 = recurrencia(a, b, c, elem+1, ans+1, nec, esa);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
        nec = false;
    }
    else if(c[elem] == b[b.size()-1]){
        esa = true;
        nec = true;
        int res1 = recurrencia(a, b, c, elem+1, ans+1, nec, esa);
        esa = false;
        int res2 = recurrencia(a, b, c, elem+1, ans, nec, esa);
        if(res1 < res2)
            ans = res1;
        else
            ans = res2;
        nec = false;
    }

    return ans;
}

signed main(){
    int t; cin >> t;
    for(int k = 0; k<t; k++){
        string conta, contb, c; cin >> conta >> contb >> c;
        string a;
        string b;
        for(int i = conta.size()-1; i>=0; i--){
            a += conta[i];
        }
        for(int i = contb.size()-1; i>=0; i--){
            b += contb[i];
        }
        int ans = 0;
        int elem = 0;
        bool nec = false;
        bool esa = false;
        cout << recurrencia(a, b, c, elem, ans, nec, esa) << endl;
    }
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


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

#include<algorithm>

#define int long long

using namespace std;

int e[100010];

bool cmd(int a,int b)

{

	return a>b;

}

signed main()

{

	ios::sync_with_stdio(false);

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

	int t;

	cin>>t;

	while(t--)

	{

		int n,l,r;

		cin>>n>>l>>r;

		int ans = 0;

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

		{

			cin>>e[i];

			if(i>=l&&i<=r)

				ans+=e[i]; 

		}

		int j = 0;

		sort(e+1,e+l);

		sort(e+l,e+r+1,cmd);

		sort(e+r+1,e+n+1);

		int kk = l;

		int k = 0;

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

		{

			if(e[i]<e[kk] && kk <= r)

			{

				k+=e[kk] - e[i];

				kk++;

			}

			else

				break;

		}

		j = k;

		kk = l;

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

		{

			if(e[i]<e[kk] && kk <= r)

			{

				k+=e[kk] - e[i];

				kk++;

			}

			else

				break;

		}

		if(j<k)

			j = k;

		cout<<ans-j<<'\n';

	}

	return 0;

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

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

#include<algorithm>

#define int long long

using namespace std;

int e[100010];

bool cmd(int a,int b)

{

	return a>b;

}

signed main()

{

	ios::sync_with_stdio(false);

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

	int t;

	cin>>t;

	while(t--)

	{

		int n,l,r;

		cin>>n>>l>>r;

		int ans = 0;

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

		{

			cin>>e[i];

			if(i>=l&&i<=r)

				ans+=e[i]; 

		}

		int j = 0;

		sort(e+1,e+l);

		sort(e+l,e+r+1,cmd);

		sort(e+r+1,e+n+1);

		int kk = l;

		int k = 0;

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

		{

			if(e[i]<=e[kk] && kk <= r)

			{

				k+=e[kk] - e[i];

				kk++;

			}

			else

				break;

		}

		j = k;

		kk = l;

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

		{

			if(e[i]<=e[kk] && kk <= r)

			{

				k+=e[kk] - e[i];

				kk++;

			}

			else

				break;

		}

		if(j<k)

			j = k;

		cout<<ans-j<<'\n';

	}

	return 0;

}

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

#include<algorithm>

#define int long long

using namespace std;

int e[100010];

bool cmd(int a,int b)

{

	return a>b;

}

signed main()

{

	ios::sync_with_stdio(false);

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

	int t;

	cin>>t;

	while(t--)

	{

		int n,l,r;

		cin>>n>>l>>r;

		int ans = 0;

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

		{

			cin>>e[i];

			if(i>=l&&i<=r)

				ans+=e[i]; 

		}

		int j = 0;

		sort(e+1,e+l);

		sort(e+l,e+r+1,cmd);

		sort(e+r+1,e+n+1);

		int kk = 1;

		int k = 0;

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

		{

			if(e[i]>e[kk] && kk < l)

			{

				k+=e[i] - e[kk];

				kk++;

			}

			else

				break;

		}

		j = k;

		kk = r + 1;

		k = 0;

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

		{

			if(e[i]>e[kk] && kk <= n)

			{

				k+=e[i] - e[kk];

				kk++;

			}

			else

				break;

		}

		if(j<k)

			j = k;

		cout<<ans-j<<'\n';

	}

	return 0;

}