ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rev(i, a, b) for (int i = a; i >= (b); i--)
#define fr first
#define sc second
#define pb push_back
#define endl "\n"

template<class T, class U> inline void chmin(T& a, U b) { if (a > b) a = b; }
template<class T, class U> inline void chmax(T& a, U b) { if (a < b) a = b; }

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//void reset() {}

void solve_task() {
    int n,k;cin >> n >> k;
    vector<ll> a(n);
    map<ll,ll> cnt;

    rep(i,0,n) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    sort(all(a),[&](int x,int y) {
        if(cnt[x] == cnt[y]) return x < y;
        return cnt[x] < cnt[y];
    });

    rep(i,0,k) a[i] = a[n - 1];

    sort(all(a));
    int ans = 1;
    rep(i,1,n) ans += (a[i] != a[i - 1]);
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int tc = 1;cin >> tc;
    while(tc--) solve_task();

    return 0;
}

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

int main() {
    
    int t;
    cin>>t;
    
    while(t--) {
        int n, k;
        cin>>n>>k;
        
        vector<int> a(n);
        map<int, int> freqMp;
        for(int i = 0; i < n; i++) {
            cin>>a[i];
            freqMp[a[i]]++;
        }
        
        vector<int> freqArr;
        for(auto it: freqMp) {
            freqArr.push_back(it.second);
        }
        
        int ans = freqArr.size();
        sort(freqArr.begin(), freqArr.end());
        
        int i = 0; 
        while(i < freqArr.size() && freqArr[i] <= k) {
            k -= freqArr[i];
            ans--;
            i++;
        }
        
        if(ans == 0) ans = 1;
        
        cout<<ans<<endl;
    }
    
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 109 ms):
#include<bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int n;
		bool f = 1;
		scanf("%d%d", &n, a);
		for (int i = 1;i < n;i++) {
			scanf("%d", a + i);
			if (a[i - 1] > a[i])f = 0;
			a[i] -= min(a[i], a[i - 1]);
		}
		printf("%s\n", f ? "YES" : "NO");
	}
	return 0;
}

Solution 2 (runtime: 327 ms):
#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
void work() {
	memset(a, 0, sizeof a);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i<n; i++) {
		if (a[i] >a[i+1]) {
			cout << "No" << endl;
			return;
		}
		else {
			int itemp = min(a[i], a[i + 1]);
			if (a[i] - itemp >= a[i - 1]) {
				a[i] -= itemp;
				a[i + 1] -= itemp;
			}
		}
	} 
	cout << "Yes" << endl;
	return;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int testcase;
	cin >> testcase;
	while (testcase--) {
		work();
	}
	
	return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

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



const int N = 510;



int n;

char str[N];



void work() {

    std::cin >> n;

    std::cin >> str;



    bool exist_p = 0, exist_s = 0;

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

        if (str[i] == 'p') {

            if (i != n - 1)

                exist_p = 1;

        } else if (str[i] == 's') {

            if (i != 0)

                exist_s = 1;

        }

    }

    

    if (exist_p && exist_s)

        std::cout << "No" << '\n';

    else

        std::cout << "Yes" << '\n';

}



int main() {

    std::ios::sync_with_stdio(0);

    std::cin.tie(0);



    int T;

    std::cin >> T;



    while (T --)

        work();

    

    return 0;

}



/*

 *  心中无女人

 *  比赛自然神

 *  模板第一页

 *  忘掉心上人

**/

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

using namespace std;

#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<int,int> PII;

typedef long long ll;

void sol(){

  int n;

  cin>>n;

  string s;

  cin>>s;

  int res1=0,res2=0;

  int ans1=-1,ans2=-1;

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

  {

  	if(s[i]=='p')

  	{

  		res1++;

  		ans1=i;

	  }

	  if(s[i]=='s')

	  {

	  	res2++;

	  	ans2=i;

	  }

  }

  if(res1==0||res2==0)

  {

  	cout<<"YES"<<endl;

  }

  else if(res1==1&&ans1==n-1)

  {

  	cout<<"YES"<<endl;

  }

  else if(res2==1&&ans2==0)

  {

  	cout<<"YES"<<endl;

  }

  else

  {

  	cout<<"NO"<<endl;

  }

}

int main()

{

	ios;

	int t;

	cin>>t;

	while(t--)

	{

		sol();

	}

	return 0;

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

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

int main() {
    int t;
    cin >> t;
    while (t--) {
        string s;
        cin >> s;

        int sum = 0, c2 = 0, c3 = 0;

        for (auto c : s) {
            sum += c - '0';
            if (c == '2') c2++;
            if (c == '3') c3++;
        }

        int rem = (9 - sum % 9) % 9;
        bool found = false;

        for (int i = 0; i <= c3; i++) {
            int diff = (rem - 6 * i) % 9;
            if (diff < 0) diff += 9;
            if ((diff * 5) % 9 <= c2) {
                found = true;
                break;
            }
        }

        cout << (found ? "YES" : "NO") << endl;
    }
    return 0;
}


Solution 2 (runtime: 46 ms):
#include <iostream>
#include<map>
#include<vector>
#include <set>
#include <algorithm>
#include<string>
#include<queue>
#include<stack>
#include <iomanip>//设置输出精度
#include<list>
#include<cmath>
#include<deque>
#define int long long
#define float  double
using namespace std;
#define PI pair<int,int>
#define PII pair<char,char>
const int N= 1e6;
int a[N],b[N],c[N];
int n;
int quickpow(int a, int b) {
	int sum = 1;
	while (b) {
		if (b & 1)
			sum *= a;
		b >>= 1;
		a *= a;
	}
	return sum;
}
int gcd(int x, int y)
{
	int r;
	while (x % y != 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

bool check(int index) {
	copy(a + 1, a + index, c + 1);
	copy(a + index + 1, a + n+1, c+index);
	int m = n - 1;
	for (int i = 1; i < m; i++)
		b[i] = gcd(c[i], c[i + 1]);
	for (int i = 1; i < m-1; i++)
		if (b[i] > b[i + 1])
			return false;
	return true;
}

void solve() {
	string s;
	cin >> s;
	int number_3 = 0;
	int number_2 = 0;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		int a = s[i] - '0';
		if (a == 3)
			number_3++;
		if (a == 2)
			number_2++;
		ans += a;
		ans = ans % 9;
	}
	if (ans == 0) {
		cout << "yes" << endl;
		return;
	}
	for (int i = 0; i <= number_3; i++) {
		for (int j = 0; j <= number_2; j++) {
			if ((ans + i * 6 + j * 2) % 9 == 0)
			{
				cout << "yes" << endl;
				return;
			}
		}
	}
	cout << "no" << endl;
}
signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(8);
	int T;
	cin >> T;
	while (T--)
		solve();
	return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 61 ms):
#include<iostream>
#include <algorithm>
#include <vector>
#include<math.h>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define isON(n,k) ((n>>k)&1)
#define ON(n,k)  (n|(1<<k))
#define OFF(n,k) (n&(~(1<<k)))
#define twopowx(x) (1<<x)

int n,oo=1000000007,c=1,k,mn=1e9+9,m;

signed main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int t;cin>>t;
  while(t--)
{
  int l,r;cin>>l>>r;m=-1;
  int x=0,y=0;
  for(int i=0;i<=30;i++)
  {
    if(isON(l,i))x=i;
    if(isON(r,i))y=i;
  }
  
    int a=0,b=0,c=0,z=0;
for(int i=30;i>=0;i--)
{
 if(isON(r,i)&&!isON(l,i)&&z!=1){a+=twopowx(i);z=1;x=twopowx(i);}
 else if(isON(l,i)&&isON(r,i)&&!z){b+=twopowx(i);c+=twopowx(i);a+=twopowx(i);}
 else if(z)
 {
  if(!isON(l,i))
  {
    c+=twopowx(i);
    b+=(twopowx(i)-1);
    break;
  }
  else 
  {
    c+=twopowx(i);
    b+=twopowx(i);
  }
 }
}

if(b==c)c=r;


cout<<a<<" "<<b<<" "<<c<<"\n";
 // cout<<(a^b)+(b^c)+(a^c)<<"\n";
 // cout<<(u^o)+(o^p)+(u^p)<<"\n";

}

}

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

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

    int a = 0, b = 0, c = 0;
    
    for (int i = 30; i >= 0; --i) {
        int d1 = ((l >> i) & 1);
        int d2 = ((r >> i) & 1);

        if (d1 == d2 and d1 == 1) {
            a |= (1 << i);
            b |= (1 << i);
        }
        else if (d1 != d2) {
            a |= (1 << i);
            for (int j = i - 1; j >= 0; --j) {
                b |= (1 << j);
            }
            break;
        }
    }

    for (int i = l; i <= r; ++i) {
        if (i != a and i != b) {
            c = i;
            break;
        }
    }

    cout << a << " " << b << " " << c << "\n";
}

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

    int t;
    cin >> t;

    while (t--) {
        solve();
    }
}
Problem: 2050B - Transfusion
Language: c++17 

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

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int it = 0; it < t; it++) {
        int n;
        cin >> n;
        long long odd_sum = 0, even_sum = 0;
        long long odd_cnt = 0, even_cnt = 0;
        for (int i = 0; i < n; i++) {
            long long a;
            cin >> a;
            if (i % 2 == 0) {
                even_cnt++;
                even_sum += a;
            } else {
                odd_cnt++;
                odd_sum += a;
            }
        }

        bool b = (even_cnt * odd_sum == odd_cnt * even_sum) &&
            (even_sum % even_cnt == 0);
        cout << (b ? "YES" : "NO") << endl;
    }
    return 0;
}

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

#include<vector>

using namespace std;

int main() {

    int t;

    cin>>t;

    while(t--){

        int n;

        cin>>n;

        vector<int> arr(n);

        long long seven=0;

        long long sodd=0;

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

            cin>>arr[i];

            if((i+1)%2==1){

                sodd+=arr[i];

            }

            else{

                seven+=arr[i];

            }

        }

        if(seven% (n/2) != 0  ||  sodd%(n-n/2)!=0){

            cout<<"NO"<<endl;

        }

        else if(seven/(n/2) == sodd/(n-n/2)){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }



    return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 998244353;
const int MAXN = 200005;
vector<int> fact(MAXN), inv_fact(MAXN);
vector<bool> is_prime(100001, true);
vector<int> divcount(1e5+1,0);
void sieve() {
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= 100000; i++) {
        if (is_prime[i]) {
            for (int j = i * i; j <= 100000; j += i) {
                is_prime[j] = false;
            }
        }
    }
    for (int i = 2; i <= 100000; i++) {
        // if (is_prime[i])
        {
        	for(int j=i;j<=1e5;j+=i)
        	{
        		divcount[j]++;
        	}
        }
    }
}

int mod_exp(int base, int exp, int mod) {
    int result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}
void precompute() {
    fact[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    inv_fact[MAXN - 1] = mod_exp(fact[MAXN - 1], MOD - 2, MOD);
    for (int i = MAXN - 2; i >= 0; i--) {
        inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD;
    }
}
int nCr(int n, int r) {
    if (r > n || r < 0) return 0;
    return (fact[n] * inv_fact[r] % MOD) * inv_fact[n - r] % MOD;
}
void dfs(vector<int>& vis,int node,vector<vector<int>>& adj,vector<int>& s,int& sz)
{
	sz++;
	s.push_back(node);
	vis[node]=1;
	for(auto it:adj[node])
	{
		if(!vis[it])
		dfs(vis,it,adj,s,sz);
	}
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // precompute(); 
    // sieve();
    int t=1;
    cin >> t;
    while (t--) {
    	int l,r;
    	cin>>l>>r;
    	int cnt=32;
    	for(int i=32;i>0;i--)
    	{
    		int bit1=((1<<i)&l);
    		int bit2=((1<<i)&r);
    		if(bit1!=bit2)
    		{
    			break;
    		}
    		else 
    		{
    			cnt--;
    		}
    	}
    	int add=0,sub=0;
    	for(int i=cnt;i>=0;i--)
    	{
    		int bit1=((1<<i)&l);
    		int bit2=((1<<i)&r);
    		if(bit1==bit2)
    		{
    			if(bit1==0)
    			{
    				add+=(1<<i);
    			}
    			else
    			{
    				sub+=(1<<i);
    			}
    		}
    	}
    	cout<<l+add<<" "<<r-sub<<" ";
    	if(add==0)
    	{
    		if(r-sub==l+1)
    		cout<<r<<endl;
    		else
    		cout<<l+1<<endl;
    	}
    	else
    	{
    		cout<<l<<endl;
    	}
    	
    	
  }
}

Solution 2 (runtime: 61 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int _;
    cin >> _;
    while (_--)
    {
        int l, r, ms, a, b, c;
        cin >> l >> r, ms = __lg(l ^ r);
        a = 1 << ms;
        for (int i = ms + 1; i <= 30; i++)
            if ((l & (1 << i)))
                a += 1 << i;
        b = a - 1;
        for (c = l; c == a || c == b; c++)
            ;
        cout << a << ' ' << b << ' ' << c << '\n';
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <stdio.h>
#include <string.h>

#define MIN(x, y) ((x)<=(y)?(x):(y))

const int N = 1e3+5, inf = N*3;

int dp[2*N][N];

int solver(const char* a, const char* b, const char* c){
    int n = strlen(a), m = strlen(b), k = strlen(c);
    for(int i=0; i<=k; ++i)
        for(int j=0; j<=n; ++j)
            dp[i][j] = inf;
    dp[0][0] = 0;
    for(int i=1; i<=k; ++i){
        for(int j=0; j<=MIN(i,n); ++j){
            if(i-j>m) continue;
            int val1 = (i-j-1>=0) ? (dp[i-1][j]+(b[i-j-1]!=c[i-1])) : inf;
            int val2 = (j-1>=0) ? dp[i-1][j-1]+(a[j-1]!=c[i-1]) : inf;
            dp[i][j] = MIN(val1, val2);
        }
    }
    return dp[k][n];
}

int main(void){
    int T;
    char a[N], b[N], c[2*N];
    scanf("%d", &T);
    while(T--){
        scanf("%s%s%s", a, b, c);
        printf("%d\n", solver(a, b, c));
    }
    return 0;
}

Solution 2 (runtime: 124 ms):


#include <bits/stdc++.h>



#define ll long long 

#define mr make_pair



using namespace std;



ll max(ll a, ll b){

    if(a>b) return a;

    return b;

}



ll min(ll a, ll b){

    if(a<b) return a;

    return b;

}



int max(int a,int b){

    if(a>b) return a;

    return b;

}



int min(int a,int b){

    if(a<b) return a;

    return b;

}



void f(vector<ll> &v,ll &n){

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

       cin>>v[i];

   }

}



void sort(vector<ll>& v){

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

}



void sort(vector<int>& v){

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

}



ll solve(string &a,string &b,string &c,ll i1,ll i2,vector<vector<ll>>& dp){

    if(i1==0 && i2==0){

        return 0;

    }

    

    if(dp[i1][i2] != -1){

        return dp[i1][i2];

    }

    

    ll maxi = LONG_MAX;

    

    if(i1>0){

        ll val = solve(a,b,c,i1-1,i2,dp);

        if(a[i1-1] == c[i1+i2-1]){

            maxi = min(maxi,val);

        }

        else if(val != LONG_MAX){

            maxi = min(maxi,1+val);

        }

    }

    

    if(i2>0){

        ll val = solve(a,b,c,i1,i2-1,dp);

        if(b[i2-1] == c[i1+i2-1]){

            maxi = min(maxi,val);

        }

        else if(val != LONG_MAX){

            maxi = min(maxi,1+val);

        }

    }

    

    return dp[i1][i2] = maxi;

}



int main(){

    ll t;

    cin>>t;

 

    while(t--){

       string a,b,c;

       cin>>a;

       cin>>b;

       cin>>c;

       

       ll n = a.length();

       ll m = b.length();

       

       vector<vector<ll>> dp(n+1,vector<ll>(m+1,-1));

       

       cout<<solve(a,b,c,n,m,dp)<<endl;

    }

    

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

Solution 1 (runtime: 46 ms):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define  DBG(x         ) cerr<<#x<<" = "<<(x)<<endl;
#define DBG2(x, y      ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<endl;
#define DBG3(x, y, z   ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<endl;
#define DBG4(x, y, z, w) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<", "<<#w<<" = "<<(w)<<endl;
#define SEPA cerr<<" ============ "<<endl;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fort(i, a, b) for(int i = int(a); i <= int(b); i++)

#define sz(s) int(s.size())
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define pb push_back
#define endl '\n'
#define fst first
#define snd second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

int r = 0;
ll solve(vector<ll> v){
    r++;
    if(sz(v) == 1) return v[0];
    vector<ll> nuevo1, nuevo2;
    ll sum = accumulate(all(v), 0LL);
    for(int i = 1; i < sz(v); i++) nuevo1.pb(v[i] - v[i - 1]);
    reverse(all(v));
    for(int i = 1; i < sz(v); i++) nuevo2.pb(v[i] - v[i - 1]);  
    ll sum1 = accumulate(all(nuevo1), 0LL);
    ll sum2 = accumulate(all(nuevo2), 0LL);
    if(sum1 > sum2) return max(solve(nuevo1), sum);
    else            return max(solve(nuevo2), sum);
}

void run_case(){
    int n; cin>>n;
    vector<ll> v(n);
    forn(i, n) cin>>v[i];
    cout<<solve(v)<<endl;
    //DBG(r)
}

int main(){
    fast_io
    //freopen("input.in", "r", stdin);
    bool mtc = true;
    int tc = 1; if(mtc) cin>>tc;
    for(int i = 0; i < tc; i++) run_case();
    return 0;
}

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

typedef long long int lld;
typedef pair<int, int> pii;

int T, N, K;
vector<lld> V(51, 0);

int main() {
    cin.tie(NULL); cin.sync_with_stdio(false);

    cin >> T;

    while (T--) {
        cin >> N;
        lld ans = 0;
        for(int i = 0; i < N; i++) {
            cin >> V[i];
            ans += V[i];
        }

        for(int i = 2; i <= N; i++) {
            lld tmp = 0;
            for(int j = 0; j <= N - i; j++) {
                V[j] = V[j + 1] - V[j];
                tmp += V[j];
            }
            ans = max(ans, abs(tmp));
        }

        cout << ans << '\n';
    }


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

Solution 1 (runtime: 171 ms):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>v(n);
        for(auto &i:v)
            cin>>i;
        sort(v.begin(),v.begin()+l-1);
        sort(v.begin()+l-1,v.begin()+r);
        sort(v.begin()+r,v.end());
        // for(auto ele:v)
        //     cout<<ele<<" ";
        // cout<<"\n";
        long long sum=accumulate(v.begin()+l-1,v.begin()+r,0LL);
        long long i=0,j=r-1,sum1=sum;
        while(v[i]<=v[j] and i<l-1 and j>=l-1)
        {
            sum1-=v[j];
            sum1+=v[i];
            i++;
            j--;
        }
        i=r-1,j=r;
        while(v[i]>=v[j] and i>=l-1 and j<n)
        {
            sum-=v[i];
            sum+=v[j];
            i--;
            j++;
        }
        cout<<min(sum1,sum)<<"\n";
    }
}



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

using namespace std;



typedef long long ll;



void solve() {



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

    vector<int>v(n+1),ans1,ans2;

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

        cin>>v[i];

        int siz = r-l+1 , ans = 0;

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

            ans1.push_back(v[i]),ans2.push_back(v[i]);

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

            ans1.push_back(v[i]);

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

            ans2.push_back(v[i]);

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

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

        ll sum1 = 0 , sum2 = 0;

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

            sum1 += ans1[i];

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

            sum2 += ans2[i];

        cout<<min(sum1,sum2)<<endl;

}

int main() {



    int t ; cin>>t;

    while(t--)

        solve();

    return 0;

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

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

using namespace std;

int main(){

	int t;

	cin>>t;

	while(t--){

		int n,l,r;

		cin>>n>>l>>r;

		vector<int> a(n);

		vector <int> left;

		vector <int> curr;

		vector<int> right;

		long long  sum=0;

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

			cin>>a[i];

			if(i<l-1){

				left.push_back(a[i]);

			}

			else if(l-1<=i && i<=r-1){

				curr.push_back(a[i]);

				sum+=a[i];

			}

			else{

				right.push_back(a[i]);

			}

	}

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

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

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

	

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

	long long lefans=sum;

	while(i>=0 && j<left.size()){

	if(curr[i]>left[j]){

		lefans=lefans+left[j]-curr[i];

		j++;

		i--;

	}

	else{

	i--;

}

	}

	

	int x=curr.size()-1,y=0;

	long long rigans=sum;

	

	while(x>=0 && y<right.size()){

	if(curr[x]>right[y]){

		rigans=rigans+right[y]-curr[x];

		y++;

		x--;

	}

	else{

	x--;

}

	}

	cout<<min(sum,min(lefans,rigans))<<endl;

}

	

}

Solution 2 (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;

       

       vector<int> v(n);

       

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

           cin>>v[i];

           

       }

       

       vector<int> vrr;

       vector<int> brr;

       

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

           if(i >=0 && i<=r-1){

               vrr.push_back(v[i]);

           }

       }

       

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

           if(j>=l-1 && j<=n-1){

               brr.push_back(v[j]);

           }

       }

       

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

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

       

       long long sum1=0;

       long long sum2=0;

       

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

           sum1=sum1+vrr[i];

           

       }

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

           sum2=sum2+brr[i];

       }

       

       long long mini=min(sum1,sum2);

       

       cout<<mini<<endl;

       

      

       

       

   }  

   return 0;

   

}