ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: c++17 

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

#define ll long long

#define ull unsigned long long

using namespace std;

int test=1;

 

 

void solve()

{

    ll  n, l , r;

    cin>>n>>l>>r;

    vector<ll> a(n + 1,  0);

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



    sort(a.begin() + 1, a.begin() + l);

    sort(a.begin() + l , a.begin() + r + 1);

    sort(a.begin() + r + 1, a.begin() + n + 1);

   //for(int i = 0; i < n; i++) cout<<a[i]<<" ";

    //cout<<endl;

    ll curr = 0;

    for(int i = l; i <= r; i++) curr+=a[i];

    //cout<<curr<<" ";

    ll mini = curr, mini2 = curr;

    ll sum1 = curr, sum2 = curr;

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

    {

            sum2 +=  a[r + i] - a[r-i+1];

            mini2 = (ll)min(mini2, sum2);

    }

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

    {

        sum1+= a[i] - a[r-i+1];

        mini = (ll)min(sum1, mini);

    }

    cout<<min(mini, mini2)<<endl;



   





}

 

 

int main()

{

  ios::sync_with_stdio(0);

  cin.tie(0);

  

  cin>>test;

  while(test--)

   solve();

 

  return 0;

}

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

using namespace std;

#define int long long

#define ld long double

#define mod 1000000007

#define modd 998244353

#define pb push_back

#define Yes cout<<"YES\n"

#define No cout<<"NO\n"

#define ff first

#define ss second

#define vi vector<long long>

#define pii pair<long long, long long>

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

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

const int inf = 2e18;

vector<pii> directions{ {0,1}, {1,0}, {0,-1}, {-1,0}, {1,1}, {1,-1}, {-1,1}, {-1,-1} };

void print(int arr[],int n,string label="") {cout<<label;for(int i=0;i<n;i++) cout<<arr[i]<<" ";cout<<"\n";}

void print(vector<int> v,string label="") {cout<<label;for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<"\n";}

int modPow(int a,int b,int p) {int ans=1;while(b>0){if((b&1)==1)ans=ans*a%p;a=a*a%p;b>>=1;}return ans;}

int modDiv(int a,int b,int p) {return a * modPow(b,p-2,p) % p;}

bool isPow2(int n) {return (n>0 && (n&(n-1)) == 0);}

int power(int a,int b) {int ans=1;while(b>0){if((b&1)==1)ans=ans*a;a=a*a;b>>=1;}return ans;}

int squareroot(int n) {int s=0,e=n;int ans;while(s<=e){int m=(s + e)/2;if(m*m<=n){s=m+1;ans=m;}else{e=m-1;}}return ans;}



void solve(int testcase)

{

    #define TESTCASES

    int n,l,r;

    cin>>n>>l>>r;

    vi a(n);

    for(int &x : a) cin>>x;

    l--;r--;

    vi al,ar;

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

        if(i <= r) al.pb(a[i]);

        if(i >= l) ar.pb(a[i]);

    }

    sort(all(al));

    sort(all(ar));

    int s1 = 0, s2 = 0;

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

        s1 += al[i];

        s2 += ar[i];

    }

    cout<<min(s1,s2)<<'\n';

}

signed main() {

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



    int t=1;

    #ifdef TESTCASES

    cin>>t;

    #endif

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

    {

        solve(i);

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <iostream>
#include <vector>
using namespace std;
#define int long long int

bool solve(string &s, int sum) {
    int n = s.size();
    vector<vector<bool> > dp(n + 1, vector<bool>(9, false));
    dp[0][sum % 9] = true;
    for (int i = 0; i < n; ++i) {
        int x = s[i] - '0';
        for (int mod = 0; mod < 9; ++mod) {
            if (!dp[i][mod]) continue;
            dp[i + 1][mod] = true;
            if (x * x <= 9) {
                int newMod = (mod - x + x * x + 9) % 9;
                dp[i + 1][newMod] = true;
            }
        }
    }
    return dp[n][0];
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;
        int sum = 0;
        for (char c : s) {
            sum += c - '0';
        }
        if (sum % 9 == 0 || solve(s, sum)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


Solution 2 (runtime: 78 ms):
#include<iostream>

#include<string>

#include<map>

using namespace std;

void solve() {

	string n;

	cin >> n;

	int len = n.size();

	int mod = 0;

	int n2 = 0, n3 = 0;

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

		if (n[i] == '2')n2++;

		if (n[i] == '3')n3++;

		int num = n[i] - '0';

		mod += num % 9;

		mod %= 9;

	}

	n2 = min(9, n2);

	n3 = min(9, n3);

	map<int, int>mp1, mp2,mp3;

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

		mp1[2 * (i + 1)] ++;

	}

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

		mp2[6 * (i + 1)] ++;

	}

	if (mod == 0) {

		cout << "YES\n";

		return;

	}

	if (!mp1.empty())mp3 = mp1;

	else mp3 = mp2;

	for (auto x : mp1) {

		for (auto y : mp2) {

			mp3[x.first]++;

			mp3[y.first]++;

			mp3[x.first + y.first]++;

		}

	}

	for (auto x : mp3) {

		if ((x.first + mod) % 9 == 0) {

			cout << "YES\n";

			return;

		}

	}

	 cout << "NO\n";

}

int main() {

	int t;

	cin >> t;

	while (t--)solve();

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 327 ms):
#include <iostream>
#include <vector>
using namespace std;
void dec(vector<int>& nums, int i){
    int k=min(nums[i],nums[i+1]);
    nums[i] -= k;
    nums[i+1] -=k;
    return;
}
int check(vector<int>& nums){
    for(int i=0;i<nums.size()-1;i++){
        if(nums[i]>nums[i+1]){return 0;}
    }
    return 1;
}
int ans_fun(vector<int>& nums){
    int n=nums.size();
    if(n==0 && n==1){return 1;}
    if(nums[0]>nums[1]){return 0;}
    for(int i=0;i<n-1;i++){
        // cout<<i<<endl;
        
            // cout<<i<<" "<<i-1<<endl;
            while(nums[i]!=0 && nums[i+1]!=0){
               dec(nums,i);
            }
            
        
//     for(int i=0;i<n;i++){
//         cout<<nums[i]<<" ";
        
//     }
// cout<<endl;

    }
    // for(int i=0;i<n;i++){
    //     cout<<nums[i]<<" ";
        
    // }
// cout<<endl;
    return check(nums);
}
int main(){
    int n;
    cin>>n;
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        int n1;
        cin>>n1;
        vector<int> nums(n1);
        for(int j=0;j<n1;j++){
            cin>>nums[j];
        }
        ans[i]=ans_fun(nums);
    }
    for(int i=0;i<n;i++){
        if(ans[i]==1){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}


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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        vector<int> a(n,0);

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

            cin>>a[i];

        }

        int flag =1;

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

            if(a[i]<=a[i+1]){

                a[i+1] = a[i+1]-a[i];

                a[i] = 0;

            }

        }



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

            if(a[i]<=a[i+1]){

                flag = 1;

                // continue;

            }

            else {

                flag = 0;

                break;

            }

        }





        flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;

        

    }

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

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

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    l--; 
    
    vector<int> arr(n);
    for (int &x : arr) cin >> x;

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

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

    long long sum1 = accumulate(brr.begin() + l, brr.begin() + r, 0LL);
    long long sum2 = accumulate(crr.begin() + l, crr.begin() + r, 0LL);
    
    cout << min(sum1, sum2) << '\n';
}

int main() {
    

    int t=1;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}


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

using ll = long long;
int MOD = (int) 1e9 + 7; // 998244353;
int di[] = {0, 0, 1, -1}, dj[] = {1, -1, 0, 0};

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    --l, --r;
    ll a[n]; for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + l);
    sort(a+l, a+r+1);
    sort(a+r+1, a+n);
    ll orig_sum = 0; for (int i = l; i <= r; ++i) orig_sum += a[i];
    int i = 0, j = r;
    ll left = orig_sum;
    while (i < l && j >= l) {
        if (a[j] > a[i]) {
            left -= a[j] - a[i];
            ++i;
            --j;
        } else {
            break;
        }
    }
    ll right = orig_sum;
    i = r+1, j = r;
    while (j >= l && i < n) {
        if (a[j] > a[i]) {
            right -= a[j] - a[i];
            ++i;
            --j;
        } else {
            break;
        }
    }
    cout << min(left, right) << '\n';
}

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

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 1093 ms):
#include<bits/stdc++.h>
#define MAX 210011
using namespace std;
vector<int > tree[MAX];
int sh[MAX];
void solve(){
	int n,ans=0;cin>>n;
	memset(sh,0,sizeof(sh));
	for(int i=1;i<n;i++){
		int a,b;cin>>a>>b;
		sh[a]++,sh[b]++;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	multiset<int >p;
	for(int i=1;i<=n;i++)
		p.insert(sh[i]);
	for(int i=1;i<=n;i++){
		int sum=1;
		p.erase(p.find(sh[i]));
		for(int y=0;y<sh[i];y++){
			p.erase(p.find(sh[tree[i][y]]));
			p.insert(sh[tree[i][y]]-1);
		}
		sum+=sh[i]-1;
		sum+=*p.rbegin()-1;
		for(int y=0;y<sh[i];y++){
			p.erase(p.find(sh[tree[i][y]]-1));
			p.insert(sh[tree[i][y]]);
		}
		ans=max(ans,sum);
		p.insert(sh[i]);
	}
	cout<<ans;
	cout<<endl;
	for(int i=1;i<=n;i++)tree[i].clear();
} 
int main()  
{
	int T;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}



Solution 2 (runtime: 828 ms):
#include<bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define endl '\n';
#define __builtin_popcount(x) __builtin_popcountll(x)
using namespace std;

#ifdef LOCAL
#include "debuglib.h"
#else
#endif

const int INF=1e17;
const int M=1e9+7;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};

void test_cases(){
	int n;
	cin >> n;
	vector<vector<int>> adj(n);
	vector<int> deg(n);
	for(int i=0;i<n-1;i++){
		int u, v;
		cin >> u >> v;
		--u, --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		++deg[u], ++deg[v];
	}
	
	if(n == 2){
		cout << 0 << endl;
		return;
	}
	
	multiset<pair<int, int>> degs;
	for(int i=0;i<n;i++){
		degs.insert(make_pair(deg[i], i));
	}
	
	int ans=0;
	for(int i=0;i<n;i++){
		int first=deg[i];
		degs.erase(make_pair(deg[i], i));
		for(int x: adj[i]){
			degs.erase(make_pair(deg[x], x));
		}
		
		int second=0;
		if(!degs.empty()){
			second=(*degs.rbegin()).first;
		}
		
		degs.insert(make_pair(deg[i], i));
		for(int x: adj[i]){
			degs.insert(make_pair(deg[x], x));
		}
		
		ans=max(ans, first+second-1);
	}
	
	for(int i=0;i<n;i++){
		for(int x: adj[i]){
			ans=max(ans, deg[i]+deg[x]-2);
		}
	}
	
	cout << ans << endl;
}

int32_t main(){
	fastio;
	int t=1;
	cin >> t;
	while(t--){
		test_cases();
	}
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
int solve(int i,int j,int k,int &x,int &y,int &z,string &a,string &b,string &c,vector<vector<int>>&dp)   //int val,int&mn,
{
    if(dp[i][j]!=-1) return dp[i][j];
    if(k==z)
    {
        return dp[i][j]=0;
    }
    int va=INT_MAX;
    int vb=INT_MAX;
    if(i<x)
    {
        // if(a[i]==c[k])va=solve(i+1,j,k+1,x,y,z,a,b,c,dp);
        // else va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+1;



        va=solve(i+1,j,k+1,x,y,z,a,b,c,dp)+(((a[i]!=c[k])));
        // ***************************************************************
    
    
    
    }
    if(j<y)
    {
       
        vb=solve(i,j+1,k+1,x,y,z,a,b,c,dp)+(b[j]!=c[k]);
    }
    return dp[i][j]=min(vb,va);
}
int main()
{
    
    int t;
    cin>>t;
    // cin.ignore();
    while(t--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        int x=a.size(),y=b.size(),z=c.size();
        vector<vector<int>>dp;
        dp.assign(x+1,vector<int>(y+1,-1));
        // getline(cin,a);
        // getline(cin,b);
        // getline(cin,c);
        // int mn=INT_MAX;
        
        cout<<solve(0,0,0,x,y,z,a,b,c,dp)<<"\n";
        // cout<<mn<<"\n";
        // for(int i=0;i<2001;i++)
        // for(int j=0;j<2001;j++)
        // dp[i][j]=-1;
        
    }
    return 0;
}

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

int32_t main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	int t; cin >> t;
	while(t--){
		string a,b,c; cin >> a >> b >> c;
        int l=0,r=0;
        int n = a.length();
        int m = b.length();
        a = " " + a;
        b = " " + b;
        c = " " + c;
        
        vector<vector<int>> dp(n+1,vector<int>(m+1,1e9));
        dp[0][0] = 0;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=m;j++){
                if(i)dp[i][j] = min(dp[i-1][j] + (a[i] != c[i+j]),dp[i][j]);
                if(j)dp[i][j] = min(dp[i][j-1] + (b[j] != c[i+j]),dp[i][j]);
            }
        }
        cout << dp[n][m] << endl;
	}
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

#define int long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define rep(i, n) for (auto i = 1; i <= n; ++i)
#define per(i, n) for (auto i = n; i >= 1; --i)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()

const int MAXN = 2e5 + 10;
const int INF = 1e18 + 5;
const int MOD = 1e9 + 7;

void solve() {
    string s;
    cin >> s;
    int n = s.size();

    for (int i = 0; i < n; ++i) {
        int mx = s[i] - '0', mxi = i;
        for (int j = i + 1; j < min(n, i + 10); ++j) {
            if (((s[j] - '0') - j + i) > mx) {
                mx = (s[j] - '0') - j + i;
                mxi = j;
            }
        }
        s[mxi] = ((s[mxi] - '0') - mxi + i) + '0';

        for (int j = mxi; j > i; --j) {
            swap(s[j], s[j - 1]);
        }
    }
    cout << s << '\n';
}

void setIO(string name = "") {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (!name.empty()) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}

int32_t main() {
    setIO();
    int tt = 1;
    cin >> tt;

    while (tt-- > 0) solve();
}


Solution 2 (runtime: 92 ms):
#include<iostream>

#include<vector>

#define gor(i,n) for(int i=1; i<n; i++)

using namespace std;

void solve(string &s ){

gor(i,s.size()){

if(s[i]-s[i-1]>1) {swap(s[i],s[i-1]); s[i-1]--;

if(i>1) i-=2;

else i--;

}

}

}



int main(){



int t; cin>>t;

while(t--){

string s; cin>>s;

solve(s);

cout<<s<<endl;

}

}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 374 ms):
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
typedef vector<int> vi;

bool helper(int x, map<int, int> &bank, int &n, int &m)
{
    if (x < bank.begin()->first)
        return false;
    if (bank[x] > 0)
    {
        if (--bank[x] == 0)
            bank.erase(x);
        if (--n + 1 < m)
            return false;
        return true;
    }
    if (x == 1)
        return false;
    if (x % 2)
    {
        int sx = x / 2, sy = x - sx;
        return helper(sx, bank, n, m) && helper(sy, bank, n, m);
    }
    else
        return helper(x / 2, bank, n, m) && helper(x / 2, bank, n, m);
}

void solve(int n, int m, vi &a, vi &b)
{
    map<int, int> mp;
    for (int e : a)
        mp[e]++;

    for (int e : b)
    {
        if (!helper(e, mp, n, m))
        {
            cout << "NO\n";
            return;
        }
        m--;
    }

    if (!n)
        cout << "YES\n";
    else
        cout << "NO\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        vi a(n), b(m);
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 0; i < m; i++)
            cin >> b[i];
        solve(n, m, a, b);
    }
}

Solution 2 (runtime: 437 ms):
#include <bits/stdc++.h>
#define ull unsigned long long
#define ul unsigned long
#define l long
#define ll long long
using namespace std;
multiset<l> a,b;
int main()
{
	ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
	int t;
	cin>>t;
	while(t--)
	{
		a.clear();
		b.clear();
		int n,m;
		cin>>n>>m;
		ll sum1=0,sum2=0;
		for(int i=1;i<=n;i++){l temp;cin>>temp;a.insert(temp);sum1+=temp;}
		for(int i=1;i<=m;i++){l temp;cin>>temp;b.insert(temp);sum2+=temp;}
		int num=n-m;
		int book=0;
		if(sum1!=sum2)
		{
			cout<<"NO"<<endl;
			continue;
		}
		while((!a.empty()&&!b.empty()))
		{
			l amax=*a.rbegin();
			l bmax=*b.rbegin();
			if(bmax>amax)
			{
				b.erase(b.find(bmax));
				if(bmax%2==0)
					b.insert(bmax/2),b.insert(bmax/2);
				else
					b.insert(bmax/2),b.insert(bmax/2+1);
				num--;
			}
			if(bmax==amax)
				a.erase(a.find(amax)),b.erase(b.find(bmax));
			if(bmax<amax)
			{
				book=1;
				break;
			}
		}
		if(book==1)
		{
			cout<<"NO"<<endl;
			continue;
		}
		if(num!=0)
		{
			cout<<"NO"<<endl;
			continue;
		}
		if(a.empty()&&b.empty())
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
using namespace std;
void solve(){
   
    string s = "";
    cin >> s;

    int count3 =0;
    int count2 =0;
    int sum =0;
    for(int i =0; i < s.length(); i++){
        sum+=(s[i]-'0');
        if(s[i] == '3'){
            count3+=1;
        }else if(s[i] == '2'){
            count2+=1;
        }
    }

    
   
        for(int i=0; i <= min(10, count2); i++){
            for(int j =0; j <= min(10, count3); j++){

                if((sum + ((2 * i) + (6 * j))) %9 ==0){
                    cout << "YES" << endl;
                    return;
                }
            }
        }
        cout << "NO"<< endl;
    

}
int main(){
    int test =0;
    cin >>test;
    for(int i =0; i < test; i++){
        solve();
    }

    
   
}


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

#define fast_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define lli long long int
#define nl "\n"

int main() {
  fast_io;

  int t;cin>>t;
  while(t--){
    string s;cin>>s;
    lli sum=0;
    int two=0,three=0;
    for(int i:s){
      int tem=i-'0';
      if(tem==2)
        ++two;
      if(tem==3)
        ++three;
      sum+=tem;
    }

    if(sum%9==0)
      cout<<"YES"<<nl;
    else{
      bool bol= false;
      for(int i=0;i<=three;++i){
        for(int j=0;j<=two;++j){
          int mod=(sum+i*6+j*2)%9;
          if(mod==0){
            bol= true;
            break;
          }
        }
        if(bol)
          break;
      }

      if(bol)
        cout<<"YES"<<nl;
      else
        cout<<"NO"<<nl;
    }
  }

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

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

using namespace std;
#define ll long long
#define limit 200000
#define MOD 998244353
vector<ll> pow2(limit + 1);



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

	vector<ll> niz1(l - 1);
	vector <ll > niz2(r - l + 1);
	vector<ll> niz3(n - r);
	for (int i = 0; i < n; i++)
	{
		if (i < l - 1)
			cin >> niz1[i];
		else if (i >= l-1 && i < r)
			cin >> niz2[i - (l-1)];
		else
			cin >> niz3[i - r];
	}
	sort(niz1.begin(), niz1.end());
	sort(niz2.begin(), niz2.end(), greater<ll>());
	sort(niz3.begin(), niz3.end());

	std::vector<ll> cumsum1(niz1.size());
	std::partial_sum(niz1.begin(), niz1.end(), cumsum1.begin());
	std::vector<ll> cumsum2(niz2.size());
	std::partial_sum(niz2.begin(), niz2.end(), cumsum2.begin());
	std::vector<ll> cumsum3(niz3.size());
	std::partial_sum(niz3.begin(), niz3.end(), cumsum3.begin());

	ll pom = 0;
	ll pom2 = 0;
	for (int i = 0; i < niz1.size() && i < niz2.size(); i++)
	{
		ll x = cumsum2[i] - cumsum1[i];
		if (x > pom)
		{
			pom = x;
		}
		else break;
	}
	for (int i = 0; i < niz3.size() && i < niz2.size(); i++)
	{
		ll x = cumsum2[i] - cumsum3[i];
		if (x > pom2)
		{
			pom2 = x;
		}
		else break;
	}

	cout << cumsum2[r - l] - max(pom, pom2)<< endl;

}


int main()
{
	cin.tie(nullptr)->sync_with_stdio(false);

	ll n; cin >> n;

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

		solve();

	}
}

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

#define deb cout<<"#"<<endl;

#define pse system("pause");

using namespace std;

using i64=long long;

using f64=double;

using str=string;

using vint=vector<int>;

using vi64=vector<i64>;

using pii=pair<int,int>;

constexpr int inf = 2e8;

constexpr i64 inf64 = 9e18;

constexpr int md = 1e9+7;

constexpr int N = 3e5+10;



void init() {



}





void solve(){

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

    vi64 sb(n-l+2,0),sf(r+1,0),f,b;

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

        int x;cin>>x;

        if (i<=r) f.emplace_back(x);

        if (i>=l) b.emplace_back(x);

    }

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

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



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

        //cout<<f[i-1]<<' ';

        sf[i]=sf[i-1]+f[i-1];

    }

    //cout<<endl;

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

        //cout<<b[i-1]<<' ';

        sb[i]=sb[i-1]+b[i-1];

    }

    //cout<<endl;

    i64 ans=inf64;

    int d=r-l;

    for (int i=1;i+d<=r;i++) {

        ans=min(ans,sf[i+d]-sf[i-1]);

    }

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

        ans=min(ans,sb[i+d]-sb[i-1]);

    }

    cout<<ans<<'\n';

}

signed main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);

    //init();

    int _=1;

    cin>>_;

    while(_--){

        solve();

    }

}

//1 3 4 5 2 2 2 3

//
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 593 ms):
#include<iostream>
#include<vector>
#include<queue>
void solve() {
    int n, m;
    std::cin >> n >> m;
    std::priority_queue<int> a, b;
    for (int i = 0; i < n; ++ i) {
    	int x;
    	std::cin >> x;
        a.push(x);
    }

    for (int i = 0; i < m; ++ i) {
    	int x;
    	std::cin >> x;
        b.push(x);
    }

    long long sum = n - m;

    while (sum >= 0 && a.size() && b.size()) {
    	if (a.top() == b.top()) {
            a.pop();
            b.pop();
        } else if (sum > 0) {
            int u = b.top(); b.pop();
            b.push(u / 2);
            b.push(u - u / 2);
            -- sum;
        } else {
            break;
        }
    }

    if (a.empty() && b.empty()) {
    	std::cout << "YES\n";
    } else {
    	std::cout << "NO\n";
    }
}
int main(){
	int t;
	std::cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Solution 2 (runtime: 187 ms):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
//#define int long long
using namespace std;
typedef long long ll;
const int N = 3e6 + 10, p = 2;
int T = 1;
int n, m;
int a[N], b[N];
void solve() {
    cin >> n >> m;
    priority_queue<int> q1,q2;
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
        q1.push(a[i]);
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
        q2.push(b[i]);
    }
    int cnt = 0;
    while (!q2.empty()) {
        int x = q2.top();
        if (q1.empty()) {
            cout << "NO" << endl;
            return;
        }
        int y = q1.top();
        if (x == y) {
            q2.pop();
            q1.pop();
            sum -= y;
        }
        else {
            if (y > x) {
                cout << "NO" << endl;
                return;
            }
            if (sum < x) {
                cout << "NO" << endl;
                return;
            }
            if(x/2) q2.push(x / 2);
            if(x - x/2) q2.push(x - x / 2);
            q2.pop();
        }
    }
    if (!q1.empty()) {
        cout << "NO" << endl;
        return;
    }
    cout << "YES" << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> T;
    while (T--) {
        solve();
        //cout << endl;
    }
    return 0;
}