ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
int a[200005]; 
void solve()
{	
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];

	for(int i=1;i<=n-1;i++)	if(a[i]<=a[i+1])	a[i+1]-=a[i],a[i]=0;
	int ans=1; 
	for(int i=1;i<n;i++)	if(a[i]>a[i+1])	{
		ans=0;
		break;
	}
	if(!ans)	cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)	solve();	
	return 0;
 } 

Solution 2 (runtime: 93 ms):
/*❤️ وَتَوَكَّلْ عَلَى اللَّهِ ۚ وَكَفَىٰ بِاللَّهِ وَكِيلًا ❤️*/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define A7Med_Ma7Moud ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define int long long
#define float double
#define ON(n , k) ((n) | (1 << k))
#define OFF(n , k) ((n) & ~(1 << k))
#define isON(n , k) (((n) >> (k)) & 1)
using namespace __gnu_pbds;
using namespace std;

const int N = 1e6 + 10, oo = 1e18, mod = 1e9 + 7;
bool TC = true;
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSetG;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSetL;
// When used earse and less_equal or greater_equal
void Erase(orderedSetG &s, int val) {
    int rank = s.order_of_key(val);
    auto it = s.find_by_order(rank);
    s.erase(it);
}

void File() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    int n; cin >> n;
    int arr[n];
    for(auto &i : arr) {
        cin >> i;
    }
    for(int i = 0; i < n - 1; i++) {
        if(arr[i] > arr[i + 1]) {
            cout << "NO" << '\n';
            return;
        }
        arr[i + 1] -= arr[i];
        arr[i] = 0;
    }
    for(int i = 0; i < n - 1; i++) {
        if(arr[i] > arr[i + 1]) {
            cout << "NO" << '\n';
            return;
        }
    }
    cout << "YES" << '\n';
}

signed main() {
    File(), A7Med_Ma7Moud;
    if (TC) {
        int tc;
        cin >> tc;
        while (tc--) {
            solve();
        }
    } else {
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
#include<bits/stdc++.h>
using namespace std;

int t;
char s[200008];

int check(int len){
	for(int i=0;i<len-1;i++){
		if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
			return 0;
		}
	}
	return 1;
}

int main()
{
    
    scanf("%d",&t);
    while(t--){
    	scanf("%s",s);
    	int len=strlen(s);
    	if(check(len)==1){
    		printf("%s\n",s);
		} else {
			while(check(len)==0){
				for(int i=0;i<len-1;i++){
					if((s[i]-'0')<(s[i+1]-'0'-1)&&s[i+1]!=0){
						char p;
						p=s[i];
						s[i]=s[i+1]-1;
						s[i+1]=p;
					}
				}
		    }
		    printf("%s\n",s);
		}
	}
	return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s<<endl;
}
int main() {
    ll t; // Number of test cases
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 124 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ll t;
    cin>>t;
    while(t--){
        ll l,r;
        cin>>l>>r;
        ll a,b,c;
        ll ans=0;
        for(int i=30;i>=0;i--){
            ll b1=0;
            ll b2=0;
            if(l & (1ll << i)) 
                b1=1;
            if(r & (1ll << i)) 
                b2=1;
            if(b1==b2){
                ans+=b1*(1ll <<i);
            }
            else{
                a=ans+(1ll << i);
                b=a-1;
                break;
            }
        }
        for(ll i=l;i<=r;i++){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << b << " " << c << endl;
    }
    return 0;
}

Solution 2 (runtime: 61 ms):
for _ in range(int(input())):
    l,r=map(int,input().split())
    low=1
    pow=0
    while low<=l:
        low*=2
        pow+=1
    l2=pow-1
    while r>=low:
        low*=2
        pow+=1
    r2=pow-1
    if l2==-1:
        print(0,1<<r2,(1<<r2)-1)
    elif r2==l2:
        x=[]
        y=[]
        k=l-(1<<r2)
        t=r-(1<<r2)
        i=0
        if k==0:
            while t>0:
                if t&1==0:
                    x.append(i)
                i+=1
                num=1<<r2
                for k in x:
                    num+=1<<k
                print(num)
                continue
        while k>0:
            if k&1==0:
                x.append(i)
            else:
                y.append(i)
            k>>=1
            i+=1
        if not(x):
            print(l,r,l+1)
        else:
            ind=len(y)-1
            while ind>0 and y[ind]-y[ind-1]==1:
                num+=1<<y[ind]
                ind-=1
            num+=1<<y[ind]
            for k in x:
                num+=1<<k
            num+=1<<r2
            print(l,r,num)
    elif r2-l2==1:
        a=1<<r2
        b=a-1
        if a-l>1:
            print(a-2,a-1,a)
        else:
            print(b,a,a+1)
    else:
        a=1<<r2
        b=(1<<r2) -1
        c=l
        print(c,b,a)
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
#include <iostream>

#include <algorithm>

using namespace std;

typedef long long LL;

int t;

LL a[100100],b[100100];

int main(){

	cin>>t;

	while(t--){

		int n,l,r,s;

		cin>>n>>l>>r;

		LL num1=0,num2=0;

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

			cin>>a[i];

			b[i]=a[i];

		}

		s=r-l+1;

		sort(a,a+r);

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

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

			num1+=a[i];

		}

		for(int j=l-1;j<l-1+s;j++){

			num2+=b[j];

		}

		if(num1>num2){

			cout<<num2<<endl;

		}

		else{

			cout<<num1<<endl;

		}

	}

}

Solution 2 (runtime: 218 ms):
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

class comp{

    public:

    bool operator()(auto a, auto b) const {

        return a.first>b.first;

    }

};

void input_matrix(vector<vector<long long>> &mat,long long m,long long n)

{

    for(long long i=0;i<m;i++)

    {

        for(long long j=0;j<n;j++)

        {

            cin>>mat[i][j];

        }

    }

}

void print_matrix(vector<vector<long long>> &mat,long long m,long long n)

{

    for(long long i=0;i<m;i++)

    {

        for(long long j=0;j<n;j++)

        {

            cout<<mat[i][j]<<" ";

        }

        cout<<endl;

    }

}

void input_vector(vector<ll> &v,ll n)

{

    for(ll i=0;i<n;i++) cin>>v[i];

}

void sort(vector<ll> &v,bool f)

{

    if(f) sort(v.begin(),v.end());

    else sort(v.rbegin(),v.rend());

}

ll mod = 1e9+7;

bool is_palindrome(vector<ll> &v)

{

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

    while(i<=j)

    {

        if(v[i++]!=v[j--]) return false;

    }

    return true;

}

vector<ll> big3(vector<ll> &arr,ll n)

{

    ll mx1=-1,mx2=-1,mx3=-1;

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

    {

        if(mx1==-1 || arr[i]>arr[mx1])

        {

            mx3 = mx2;

            mx2 = mx1;

            mx1 = i;

        }

        else if(mx2==-1 || arr[i]>arr[mx2])

        {

            mx3 = mx2;

            mx2 = i; 

        }

        else if(mx3 == -1 || arr[i]>arr[mx3]) mx3 = i;

    }

    return {mx1,mx2,mx3};

}

void solve()

{

    ll n,l,r;

    cin>>n>>l>>r;

    vector<ll> a(n);

    input_vector(a,n);

    vector<ll> a1,a2;

    for(int i=0;i<r;i++) a1.push_back(a[i]);

    for(int i=l-1;i<n;i++) a2.push_back(a[i]);

    sort(a1,1);

    sort(a2,1);

    ll ans = 1e18;

    ll sum = 0;

    for(int i=0;i<r-l+1;i++) sum+=a1[i];

    ans = min(ans,sum);

    sum = 0;

    for(int i=0;i<r-l+1;i++) sum+=a2[i];

    ans = min(ans,sum);

    cout<<ans<<endl;

}

int main() {

     ll t;

     cin >> t;

     while (t--) 

     {

        solve();

     }

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loopf(i,a,b) for(ll i=a;i<b;i++)
#define loopb(i,a,b) for(ll i=a;i>b;i--)
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define vc vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mapii map<int,int>
#define mapll map<ll,ll>
#define all(x) x.begin(),x.end()
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define read(a) for(auto &i:a)cin>>i
#define ub(v,i) upper_bound(all(v),i)
#define lb(v,i) lower_bound(all(v),i)
const ll M=1e9+7;
const ll N=51;
vc<vc<ll>>ncr_arr(N,vc<ll>(N));
ll ncr(ll n, ll r)
{
 
    long long p = 1, k = 1;
 
    if (n - r < r)
        r = n - r;
 
    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;
 
            long long m = __gcd(p, k);
 
            p /= m;
            k /= m;
 
            n--;
            r--;
        }
    }
 
    else
        p = 1;
    return p;
}
void pre(){
    loopf(i,0,N){
        loopf(j,0,N){
            if( j > i)
                continue;
            ncr_arr[i][j] = ncr(i,j);
        }
    }
}

void solve()
{
    ll n;
    cin>>n;
    vc<ll>v(n);
    read(v);
    ll sum = accumulate(all(v),0);
    loopf(i,0,n-1){
        ll first_term_1 = 0,last_term_1 = 0;
        loopf(j,0,i+1){
            first_term_1 += ncr_arr[i][j] * pow(-1,j) * v[j];
        }
        loopf(j,0,i+1){
            last_term_1 += ncr_arr[i][j] * pow(-1,j) * v[n - 1 - i + j];
        }
        // cout<<first_term_1<<" "<<last_term_1<<endl;
        sum = max(sum,abs(last_term_1 - first_term_1));
    }

    cout<<sum<<endl;
}
int main()
{
    // sieve();
    pre();
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fast
    int t=1;
    cin>>t;
    while(t--)
        solve();
}

Solution 2 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t, n;
    cin >> t;
    while (t--) {
        cin >> n;
        vector<long long> v(n);
        long long sum = 0;
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
            sum += v[i];
        }
        while (v.size() != 1) {
            vector<long long> v1(v.size() - 1);
            for (int i = 0; i < (int) v.size() - 1; ++i) {
                v1[i] = v[i + 1] - v[i];
            }
            sum = max(sum, abs(accumulate(v1.begin(), v1.end(), 0LL)));
            v = v1;
        }
        cout << sum << '\n';
    }
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define read(vec); for(auto& it : vec) cin >> it;
#define print(vec); for(auto& it : vec) cout << it << " "; cout << endl;
#define printl(vec); for(auto& it : vec) cout << it << endl;
#define srt(vec); sort(vec.begin(),vec.end());

int n,m,k,q;
vector<unordered_set<int>> g;

void solve(){
  cin >> n;
  g.clear();
  g.resize(n);
  for(int i=0;i<n-1;i++){
    int a,b; cin >> a >> b; a--; b--;
    g[a].insert(b);
    g[b].insert(a);
  }
  int mx = 0;
  vector<vector<int>> vec(n);
  for(int i=0;i<n;i++){
    vec[g[i].size()].push_back(i);
  }
  int ans = 0;
  for(int i=n-1;i>=0;i--){
    if(!vec[i].size()) continue;
    for(int j=i;j>=0;j--){
      if(!vec[j].size()) continue;
      for(auto it1:vec[i]){
        for(auto it2:vec[j]){
          if(it1 == it2) continue;
          int num = i+j-2;
          if(g[it1].find(it2) == g[it1].end()) num++;
          ans = max(ans,num);
          if(ans >= i+j-1){
            cout << ans << endl;
            return;
          }
        }
      }
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
  int t = 1; 
  cin >> t;
  while(t--){
    solve();
  }
}

Solution 2 (runtime: 1061 ms):

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int> deg(n + 1);
        vector<int> adj[n + 1];
        for(int i = 0; i < n - 1; i++) {
            int u, v;
            cin >> u >> v;
            deg[u]++;
            deg[v]++;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        multiset<int> st;
        for(int i = 1; i <= n; i++) st.insert(deg[i]);
        int maxComp = 0;
        for(int firstNode = 1; firstNode <= n; firstNode++) {
            auto itr1 = st.find(deg[firstNode]);
            if(itr1 != st.end()) st.erase(itr1);
            for(auto it: adj[firstNode]) {
                int k = deg[it];
                auto itr = st.find(k);
                if(itr != st.end()) st.erase(itr);
                st.insert(k - 1);
            }
            
            int maxVal = *st.rbegin();
            //cout << maxVal << endl;
            
            //cout << firstNode << " " << deg[firstNode] << " " << maxVal << endl;
            for(auto it: adj[firstNode]) {
                int k = deg[it];
                auto itr = st.find(k - 1);
                if(itr != st.end()) st.erase(itr);
                st.insert(k);
            }
            st.insert(deg[firstNode]);
            
            maxComp = max(maxComp, deg[firstNode] + maxVal - 1);
        }
        
        cout << maxComp << "\n";
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
void solve() {
    string s;
    cin >> s;
    int two_ct = 0, three_ct = 0, rem = 0;
    for(int i = 0; i<s.size(); i++){
        rem += s[i] - '0';
        two_ct += (s[i]=='2');
        three_ct += (s[i]=='3');
    }
    if(two_ct>8) two_ct = 8;
    if(three_ct>8) three_ct = 8;
    for(int i = 0; i<=two_ct; i++){
        for(int j = 0; j<=three_ct; j++){
            if((rem + 2*i + 6*j)%9==0){
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
    
}

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


Solution 2 (runtime: 61 ms):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
void solve()
{
    string s;cin >> s;
    ll sum = 0;
    ll sum2 = 0 , sum3 = 0;
    for(auto t : s)
    {
        sum += t - '0';
        if(t == '2') sum2++;
        if(t == '3') sum3++;
    }
    if(sum % 9 == 0) cout << "YES" << '\n';
    else
    {
        int temp = sum % 9;
        for(int i = 0;i <= sum2;i++)
        {
            for(int j = 0;j <= sum3;j++)
            {
                int t = temp + i * 2 + j * 6;
                if(t % 9 == 0)
                {
                    cout << "YES" << '\n';
                    return;
                }
            }
        }
        cout << "NO" << '\n';
    }
}
int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int _;cin >> _;
    while(_--) solve();
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>

using namespace std;

#define ll long long



void solve() {

    ll n,l,r;

    cin>>n>>l>>r;

    l--;

    r--;

    ll a[n];

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

        cin>>a[i];

    }

    vector<ll> v1,v2;

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

        v1.push_back(a[i]);

    }

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

        v2.push_back(a[i]);

    }

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

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

    ll s1=0,s2=0;

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

        s1+=v1[i];

        s2+=v2[i];

    }

    cout<<min(s1,s2)<<endl;



}



int main() {

    

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    

    return 0;

}

Solution 2 (runtime: 187 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long

void soln(){
  int n,l,r;
  cin>>n>>l>>r;
  vector<int>arr(n);
  vector<int>left,middle,right;
  int lf=0,m=0,rg=0;
  for(int i=0;i<n;i++){
    cin>>arr[i];
    if(i+1 <l){
      left.push_back(arr[i]);
      lf+=arr[i];
    }
    else if((i+1)>=l &&(i+1)<=r){
      m+=arr[i];
      middle.push_back(arr[i]);
    }
    else{
      rg+=arr[i];
      right.push_back(arr[i]);
    }
  
  }
  sort(left.begin(),left.end());
  sort(middle.begin(),middle.end());
  sort(right.begin(),right.end());
  int ans=m;
  int temp=m;
  //first with left
  int i=0;
  int j=middle.size()-1;
  while(i<left.size()&&j>=0){
    if(m-middle[j]+left[i]<m){
      m=m-middle[j]+left[i];
      j--;
      i++;
    }
    else
    break;
  }
  
  //then with right
  i=0;
  j=middle.size()-1;
  while(i<right.size()&&j>=0){
    if(temp-middle[j]+right[i]<temp){
      temp=temp-middle[j]+right[i];
      j--;
      i++;
    }
    else
    break;
  }
  cout<<min(m,min(ans,temp))<<endl;
}

int32_t main() 
{
    int t;
    cin>>t;
    while(t--)
    soln();
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 249 ms):
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
	cin>>n>>k;
	map<int,int> mp;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		mp[x]++;
	}
	vector<int> ar;
	for(auto &it: mp)
	{
		ar.push_back(it.second);
	}
	int i;
	sort(ar.begin(),ar.end());
	for(i=0;i<ar.size();i++)
	{
      if(ar[i]<=k)
      {
      	k=k-ar[i];
      }
      else 
      break;
	}
	int ans=ar.size()-i;
	cout<<max(1,ans)<<endl;

	}
	
	


}

Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(auto i=a; i<b;++i)
#define rrep(i,a,b) for(auto i=a;i>=b;--i)
#define len(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pi pair<int, int>
#define pip pair<int,pi>
#define pl pair<ll,ll>
#define plp pair<ll,pl>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define nl "\n"
#define mod 1000000007


void solve()
{
    int n,k;cin>>n>>k;
    map<int,int> mp;
    rep(i,0,n) {
      int a;cin>>a;
        mp[a]++;
    }

    vector<pi> v;
    for(auto i:mp) {
        v.pb({i.second,i.first});
    }
    sort(all(v));
    int cnt=v.size();
    for(auto i:v) {
        if(i.first<=k){
            k-=i.first;
            cnt--;
        }    
    }
    cout<<max(1,cnt)<<nl;
}


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif*/

    ll test=1;
    cin>>test;
    while(test--)
    {
        solve();
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    int p = -1;
    while (t--)
    {
        string s;
        cin >> s;
        
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] < s[i + 1])
            {
                int j = i;
                while (j >= 0 && (s[j] < s[j + 1] - 1))
                {
                    s[j + 1] = s[j + 1] - 1;
                    swap(s[j], s[j + 1]);
                    j--;
                }
            }
        }

        cout << s << endl;
    }
}


Solution 2 (runtime: 46 ms):
#include <bits/stdc++.h>



using namespace std;



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

    for(int gt=0;gt<t;gt++){

        string s;

        cin>>s;

        int f=1;

        while(f){

            f=0;

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

                int sp1=s[i]-'0',sp2=s[i-1]-'0';

                if(sp1-1>sp2){

                    sp1--;

                    char s1=s[i],s2=s[i-1];

                    s[i]=sp2+'0';

                    s[i-1]=sp1+'0';

                    f=1;

                }

            }

        }

        cout<<s<<'\n';

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 187 ms):
#include<bits/stdc++.h>

using namespace std;



int main(){

    int t;

    cin >> t;

    while(t--){

        int n, l, r;

        cin >> n >> l >> r;

        l--; 

        vector<int> arr(n);

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

            cin >> arr[i];

        }

        vector<int> brr = arr;

        sort(brr.begin()+l, brr.end());

        vector<int>crr = arr;

        sort(crr.begin(), crr.begin() + r, greater<int>());

        long long sum_brr = 0, sum_crr = 0;

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

            sum_brr += brr[i];

            sum_crr += crr[i];

        }

        cout << min(sum_brr, sum_crr) << endl;

    }

    return 0;

}

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>



#define __ std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define int long long

#define endl '\n'

#define pb push_back

#define ff first

#define ss second

#define bb begin()

#define ee end()

#define sz size()

#define CEIL(a, b) ((a) + (b - 1))/b

#define TRUNC(x) floor(x * 100) / 100

#define loop(i, a, n) for(int i=a; i < n; i++)

#define dbg(x) cout << #x << " = " << x << endl;



using namespace std;



typedef long long ll;

typedef long double ld;



const ll MOD = 1e9 + 7;

const ll LINF = 0x3f3f3f3f3f3f3f3f;

const double PI = acos(-1);



void solve() {

    int n, l, r; cin >> n >> l >> r;

    vector<int> nums(n); for(auto &x : nums) cin >> x;



    vector<int> left(nums.bb, nums.bb + r); sort(left.bb, left.ee);

    vector<int> right(nums.bb + l-1, nums.ee); sort(right.bb, right.ee);



    int qnt = r - l + 1;

    int sumLeft = 0, sumRight = 0;

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

        sumLeft += left[i]; sumRight += right[i];

    }



    cout << min(sumLeft, sumRight) << endl;

}



int32_t main() { __;

    int t; cin >> t;



    while(t--) solve();

    

    return 0;

}