ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: c++17 

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

#define endl "\n"
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long

#define vin(v, n) for (int i = 0; i < n; i++) cin >> v[i];
#define vinn(v, n) for (int i = 1; i <= n; i++) cin >> v[i];
void vout(vector<int> v, int n) { for (auto i : v) cout << i << " "; cout << endl; }
void voutt(vector<int> v, int n) { for (int i = 1; i <= n; i++) cout << v[i] << " "; cout << endl; }

#define rep(i, s, e) for (int i = s; i < e; i++)
#define repp(i, s, e) for (int i = s; i <= e; i++)
#define repn(i, s, e) for (int i = s; i >= e; i--)
#define pb push_back
#define vi vector<int>
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;

const int M = 1e9+7;

long long squareRoot(long long n){
    long long ans=1;
    long long lo=1,hi=n;
    while(hi>=lo){
        long long mid=lo+(hi-lo)/2;
        if(mid*mid<=n){
            ans=mid;
            lo=mid+1;
        }
        else hi=mid-1;
    }
    return ans;
}

int power(int a,int b){
	if(b == 0){
		return 1;
	}
	int ans = power(a, b/2);
	ans = (ans*ans)%M;
	if(b&1){
		ans = (a*ans)%M;
	}
	return ans;
}

int ceil(int a, int b){
    return (a+b-1)/b;
}

void solveyk(){

    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;
    // string s;
    // cin>>s;
    // int n=static_cast<long long>(s.size());
    // for(int i=0;i<s.size();i++){
    //     int num=s[i]-'0',pos=i;
    //     // cout<<num<<endl;
    //     for(int j=i;j<min(n,j+10);j++){
    //         if(s[j]-'0'-(j-i)>num){
    //             num=s[j]-'0'-j+i;
    //             pos=j;
    //         }
    //     }
    //     while(pos>i){
    //         swap(s[pos],s[pos-1]);
    //         pos--;
    //     }
    //     s[i]=num+'0';
    //     // cout<<s[i]<<endl;
    // }
    // cout<<s<<endl;
    
}


signed main(){
	fastio();
    int t;
    cin>>t;
    while(t--){
        solveyk();
    }
    
}

Solution 2 (runtime: 93 ms):
// https://codeforces.com/problemset/problem/2050/D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main()
{
int tt; cin >> tt;
while( tt -- ){
    string s; cin >> s;

    int n = s.size();

    for(int i = 0; i < n; i ++){
        int best = s[i] - '0';
        int pos = i;

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

        // Bubble the chosen digit (at 'pos') back to index i
        while(i < pos){
            swap(s[pos], s[pos - 1]);
            pos --;
        }

        s[i] = best + '0';

    }

    cout << s << endl;

}
return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 343 ms):
#include "bits/stdc++.h"
using namespace std;
int t,n,a;
int main(){
	cin >> t; while(t--){
		cin >> n;
		long long dan=0,dann=0,shuang=0,shuangn=0;
		for(int i=1;i<=n;i++){
			cin >> a;
			if(i%2){
				dan += a;
				dann++;
			}else{
				shuang += a;
				shuangn++;
			}
		}
		if(dan%dann==0 and shuang%shuangn==0 and dan/dann == shuang/shuangn) cout<<"yes\n";
		else cout<<"no\n";
		
	}
	
}

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

using namespace std;

int main(){

    int t;

    cin>>t;

    while(t--){

        long long n;

        cin>>n;

        long long arr[n];

        for(int i = 0 ; i<n ;i++){cin>>arr[i];}

        long long sum1 = 0, sum2 =0 ,odd = 0,even = 0;

        for(long long i =0; i<n ; i+=2){

            sum1 = sum1 + arr[i];

            odd++;

        } //odd sum

        for(long long i =1; i<n; i+=2){

            sum2 = sum2 + arr[i];

            even++;

        }//even sum

        if((sum1%odd==0)&&(sum2%even==0)&&(sum1/odd) == (sum2/even)){cout<<"YES"<<endl;}

        else{cout<<"NO"<<endl;}

        

    }

}
Problem: 2050E - Three Strings
Language: c++17 

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define x first
#define y second

const int N = 2e3 + 10;

int qmi(int a, int k, int p)  // 求a^k mod p
{
    int res = 1 % p;
    while (k)
    {
        if (k & 1) res = (LL)res * a % p;
        a = (LL)a * a % p;
        k >>= 1;
    }
    return res;
} 

int n, k;
char s1[N], s2[N], t[N];
int f[N][N];

void solve()
{
    cin >> s1 + 1 >> s2 + 1 >> t + 1;
    int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1);
    // memset(f, 0x3f, sizeof f);
    // for(int i = 0; i <= l1; i ++) f[i][0] = 0;
    // for(int j = 0; j <= l2; j ++) f[0][j] = 0;
    
    for(int i = 0; i <= l1; i ++)
        for(int j = 0; j <= l2; j ++)
        {
            f[i][j] = 0;
            if(i == 0 && j == 0) continue;
            if(i != 0) 
                f[i][j] = f[i - 1][j] + (s1[i] == t[i + j]);
            if(j != 0)
                f[i][j] = max(f[i][j], f[i][j - 1] + (s2[j] == t[i + j]));
        }
    cout << l1 + l2 - f[l1][l2] << endl;
}

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

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

using namespace std;



void InOutFast() {

    ios::sync_with_stdio(false);

    cout.tie(nullptr);

    cin.tie(nullptr);

}



#define int long long

#define bye return 0

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

#define ll long long

const int N = 2e3 + 5, oo = 1e18, mod = 1e9 + 7;

int dx[] = {-1, 0, 0, 1};

int dy[] = {0, -1, 1, 0};

int dp[N][N];

string a, b, c;

int n, m, q;

int go(int i, int j){

    int next = i + j;

    if(i == n){

        int cnt = 0;

        while(j < m) {

            if (b[j] != c[next])

                cnt++;

            j++, next++;;

        }

        return cnt;

    }

    if(j == m){

        int cnt = 0;

        while(i < n) {

            if (a[i] != c[next])

                cnt++;

            i++, next++;;

        }

        return cnt;

    }

    if(~dp[i][j])

        return dp[i][j];

    int ch1 = go(i+1, j) + (a[i] != c[next]);

    int ch2 = go(i, j+1) + (b[j] != c[next]);

    return dp[i][j] = min(ch1, ch2);

}

signed main(){

    InOutFast();

    int t;

    cin >> t;

    while(t--) {

        memset(dp, -1, sizeof dp);

        cin >> a >> b >> c;

        n = (int)a.size(), m = (int)b.size(), q = (int)c.size();

        cout << go(0, 0) << '\n';

        // comment

    }



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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const char nl = '\n';
#define all(x) x.begin(), x.end()

void solve() {
    int l, r; cin >> l >> r;
    int prefix = 0;
    for (int i=30;i>=0;i--){
                if (((1<<i)&l) != ((1<<i)&r)) {
            int a = prefix + (1<<i);
            int b = prefix + (1<<i) - 1;
            int c;
            if (b!=l) c = l;
            else c = r;
            cout << a << " " << b << " " << c << nl;
            return;
        }
        prefix += ((1<<i)&l);
    }
}
int main() {
    int t; cin >> t; while (t--) {
        solve();
    }
}

Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
// // order_of_key(k): Number of items strictly smaller than k.
// // find_by_order(k): K-th element in a set (counting from zero).

#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

signed main() {
    int test_cases = 1;
    cin >> test_cases;
    while (test_cases--) {
        int l, r;
        cin >> l >> r;
        int x = __lg(r) ;
        int a = 0, b = 0;
        for (int i = x; i >= 0; i--) {
            if (((l >> i) & 1) == ((r >> i) & 1)) {
                if ((l >> i) & 1) {
                    a |= (1LL << i);
                    b |= (1LL << i);
                }
                x--;
            }
            if (((l >> i) & 1) != ((r >> i) & 1)) {
                break;
            }
        }
        a |= ((1LL << x) - 1);
        b |= (1LL << x);
        cout << a << ' ' << b << ' ';
        for (int i = l; i <= r; i++) {
            if (i != a && i != b) {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1327 ms):
#include"bits/stdc++.h"
 
using namespace std;
 
int main(){
    int n;
    cin>> n;
 
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<pair<int,int>> b;
    unordered_set<int> s;
    for(auto it:a){
        for(int i=it+1;i<=n;i++){
            if(s.find(i)!=s.end()) continue;
            b.push_back({i,it});
        }
        for(int i=n;i>=1;i--){
            if(i==it || s.find(i)!=s.end()) continue;
            b.push_back({it,i});
        }
        s.insert(it);
    }
 
    cout<<b.size()<<endl;
    for(auto it:b){
        cout<<it.first<<" "<<it.second<<endl;
    }
    return 0;
}


Solution 2 (runtime: 327 ms):
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define Yes cout<<"YES\n"
#define No cout<<"NO\n"
#define no cout<<"No\n"
#define yes cout<<"Yes\n"
#define all(v) v.begin(),v.end()
#define inp(arr) for(auto &it:arr) cin>>it;
#define outp(arr) for(auto &it:arr) cout<<it<<" ";cout<<endl;
#define sum(arr) accumulate(all(arr),0);
#define what_is(val1) cout<<#val1<<": "<<val1<<endl;
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mach_speed  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
const int mod=1000000007;
const int INF=1000000000;

void solve() {
  int n;cin>>n;
  int arr[n];
  inp(arr);
  vector<pair<int,int>> ans;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n-1; j++)
    {
      if(arr[j]<arr[j+1]){
        ans.push_back({arr[j],arr[j+1]});
        swap(arr[j],arr[j+1]);
      }
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n-1; j++)
    {
      if(arr[j]>arr[j+1]){
        ans.push_back({arr[j],arr[j+1]});
        swap(arr[j],arr[j+1]);
      }
    }
  }
  reverse(all(ans));
  cout<<ans.size()<<endl;
  for(auto it:ans) cout<<it.first<<" "<<it.second<<endl;
}

int32_t main()
{
  mach_speed    
  // #ifdef LOCAL
  // #endif
  int t=1;
  // cin>>t;
  while (t--)
  {
    // cout<<t;
    solve();
  }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int n;
        cin>>n;
        vector<int>arr(n,0);
        for(int i=0;i<n;i++)
        cin>>arr[i];
        vector<int>temp=arr;
        int maxi=LLONG_MIN;
        while(true)
        {
            int sum=0ll;
            for(int i=0;i<temp.size();i++)
            {
                sum+=temp[i];
            }
            maxi=max(maxi,sum);
            reverse(temp.begin(),temp.end());
            if(temp.size()==1)
            break;
            vector<int>v;
            for(int i=1;i<temp.size();i++)
            {
                v.push_back(temp[i]-temp[i-1]);
            }
            sum=0;
            for(int i=0;i<v.size();i++)
            sum+=v[i];
            maxi=max(maxi,sum);
            int neg=(-1ll)*sum;
            maxi=max(maxi,neg);
            temp=v;
            if(temp.size()==1)
            {maxi=max(maxi,temp[0]);break;}
        }
        cout<<maxi<<endl;
    }
}

Solution 2 (runtime: 61 ms):
#pragma region usual_defs
#include <iostream>

// this is the only reason I like C++ (sorry, java, try to be more fun next time):
#define meow cin
#define murr cout
#define lol long long
#define el '\n'
#define none \
    {        \
    }
#define kaput return
using namespace std;
#pragma endregion usual_defs

#define i_like_cats

int n, l;
lol a[50];
lol best;
lol s;

lol sum()
{
    s = 0;
    for (int i = l; i < n; i++)
    {
        s += a[i];
    }
    kaput s;
}

void updateBest()
{
    best = max(sum(), best);
    best = max(s * -1, best);
}

void cat()
{
    meow >> n;
    l = 0;
    for (int i = 0; i < n; i++)
    {
        meow >> a[i];
    }
    best = sum();
    for (l = 1; l < n; l++)
    {
        for (int i = n - 1; i >= l; --i)
        {
            a[i] -= a[i - 1];
        }
        updateBest();
    }
    murr << best << el;
}

#pragma region main
#ifdef i_like_cats
int INPUT_SETS_COUNT;
#endif
int main()
{
    ios_base::sync_with_stdio(false);
    meow.tie(NULL);

#ifdef i_like_cats
    meow >> INPUT_SETS_COUNT;
    cin.ignore();
    while (INPUT_SETS_COUNT--)
        cat();
#endif
#ifndef i_like_cats
    cat();
#endif
}
#pragma endregion main
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

int main() {
	int t;
	cin>>t;
	while(t--){
	    ll n;
	    cin>>n;
	    
	    vector<ll>a(n);
	    for(ll i=0;i<n;i++) cin>>a[i];
	    
	    for(ll i=0;i<n-1;i++){
	        ll temp = a[i];
	        a[i] = a[i] - min(a[i],a[i+1]);
	        a[i+1] = a[i+1] - min(a[i+1],temp);
	    }
	    
	    bool ok = true;
	    for(ll i=0;i<n-1;i++){
	        if(a[i]>a[i+1]){
	            ok = false;
	            break;
	        }
	    }
	    
	    if(ok) cout<<"YES"<<endl;
	    else cout<<"NO"<<endl;
	    
	    
	}
	return 0;
}


Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) a.begin(), a.end()
typedef vector<ll> vll;
#define life ios_base::sync_with_stdio(false);
#define saver cin.tie(0);
#define f first
#define s second
#define nxt cout << endl;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
#define rep(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define rep0(i, a) rep(i, 0, a)
#define pb push_back

int main()
{
    life saver int t;
    cin >> t;
    while (t--)
    {

        int n;
        cin >> n;
        vll a(n);
        bool flag = true;
        rep0(i, n)
        {
            cin >> a[i];
        }

        ll d = a[0];
        rep(i, 1, n)
        {
            if (d > a[i])
            {
                flag = false;
                break;
            }
            else
            {
                d = a[i] - d;
            }
        }
        if (flag)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 280 ms):
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define dbg(x) cerr<<#x<<": "<<x<<"\n";

/*  
Visita
Enjambre
*/

void solve(){
    int n; cin>>n;
    vector<int>v(n);
    using T=pair<int, int>;
    vector<T>ans;
    for(int &x:v) cin>>x;
    // reverse(v.begin(), v.end());
    vector<int>aux;
    for(int i=n ; i>0 ; i--) aux.push_back(i);
    for(int i=n ; i>=1 ; i--){
        for(int j=i+1 ; j<=n ; j++){
            ans.push_back({j, i});
        }
    }
    sort(ans.begin(), ans.end());
    for(int i=0 ; i<n ; i++){
        int j;
        for(j=i ; j<n ; j++){
            if(v[i]==aux[j]) break;
        }
        // dbg(j)
        for(int k=j ; k>i ; k--){
            ans.push_back({aux[k], aux[k-1]});
            swap(aux[k], aux[k-1]);
        }
    }
    cout<<(int)ans.size()<<"\n";
    for(auto it:ans) cout<<it.first<<" "<<it.second<<"\n";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> c(n);
  for(int i = 0; i < n; i++) {
    cin >> c[i];
  }
  int m = 0;
  vector<int> a(n);
  vector<vector<int>> overtakes;
  for(int i = n; i >= 1; i--) {
    a[n - i] = i;
  }
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      overtakes.push_back({j, i});
      m++;
    }
  }
  for(int i = 0; i < n; i++) {
    int pos = lower_bound(a.begin() + i, a.end(), c[i], greater<int>()) - a.begin();
    // cout << pos << '\n';
    for(int j = pos - 1; j >= i; j--) {
      overtakes.push_back({a[j + 1], a[j]});
      swap(a[j], a[j + 1]);
      m++;
    }
  }

  // for(int i = 0; i < n; i++) {
  //   cout << a[i] << ' ';
  // }
  // cout << '\n';

  cout << m << '\n';
  for(int i = 0; i < m; i++) {
    cout << overtakes[i][0] << ' ' << overtakes[i][1] << '\n';
  }
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

typedef long long ll;
int t,n,l,r;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--)
    {
        cin>>n>>l>>r;
        l--,r--;
        vector<int>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        multiset<int>c;
        for(int i=0;i<=r;i++)
            c.insert(a[i]);
        ll res=0;
        int cnt=0;
        for(int x:c)
        {
            res+=x;
            //cout<<"@res:"<<res<<endl;
            cnt++;
            if(cnt==r-l+1)
                break;
        }
        //cout<<"res:"<<res<<endl;
        c.clear();

        ll maxn=0;
        int id=0;
        for(int i=l;i<n;i++)
            c.insert(a[i]);
        for(int x:c)
        {
            maxn+=x;
            id++;
            if(id==r-l+1)
                break;
        }
        //cout<<"maxn:"<<maxn<<endl;

        cout<<min(res,maxn)<<endl;
    }
}


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

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

using namespace std;

#define INF (int)1e18

#define int long long

typedef tree < pair<int, int> ,  null_type ,  less<pair<int, int>> ,  rb_tree_tag ,  tree_order_statistics_node_update> PBDS;

// #define vi vector<int>

// #define pb push_back

const int n1 = 4000000;

const int mod = 1e9 + 7;

int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

int fact(int n) {

    int temp = 1;

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

        temp *= (i + 1);

    }

    return temp;

}

void Solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    vector<int>v(n), v1, v2;

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

    {

        cin >> v[i];

    }

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

    {

        v1.push_back(v[i]);

    }

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

        v2.push_back(v[i]);

    }

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

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

    int cnt1 = 0, cnt2 = 0;

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

        cnt1 += v1[i];

        cnt2 += v2[i];

    }

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

}



int32_t main()

{

    auto begin = std::chrono::high_resolution_clock::now();

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    int t = 1;





    cin >> t;

    //cout << t;

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

    {

        //cout << "Case #" << i << ": ";

        Solve();



    }

    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);

    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";

    return 0;

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

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

using namespace std;





int main() {

	ios::sync_with_stdio(0); cin.tie(0);

	int t; cin >> t;

	while (t--) {

		int n, l, r;

		cin >> n >> l >> r;

		--l; --r;

		int a[n], b[n];

		long long suma = 0, sumb = 0;

		for (int i = 0; i < n; ++i) cin >> a[i], b[i] = a[i];

		sort(a, a+r+1); sort(b+l, b+n);

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

		for (int i = l; i <= r; ++i) sumb += b[i];

		cout << min(suma, sumb) << "\n";

	}

	return 0;

}



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

#include <vector>

#include <algorithm>

using namespace std;

    //1-partition array into 3 arrays from ranges : a: <l ,b: l<= <=r ,c: >r

    //3-sort the 3 subarrays

    //2- take arrays a and b and use two pointers to minimze elements picked

    //3- repeat with the b and c and answer is the minimum of steps 2 and 3

    

long long findMinSum(vector<int>& a,vector<int>& b){

    int ptrA = 0,ptrB=b.size()-1;

    long long sum =0;

    while (ptrA<a.size() && ptrB >= 0 && a[ptrA]< b[ptrB]){

        sum+=a[ptrA];

        ptrA++;

        ptrB--;

    }

    while (ptrB>=0){

        sum+=b[ptrB--];

    }

    return sum;

}



int main()

{

    int tc;

    cin >> tc;

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

        int n,l,r,element;

        cin >> n;

        cin >> l;

        cin >> r;

        vector<int> a,b,c;

        a.reserve(l);

        b.reserve(r-l+1);

        c.reserve(n-r);

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

            cin >> element;

            if (i<l){

                a.push_back(element);

            }else if (i>=l && i<=r){

                b.push_back(element);

            }else{

                c.push_back(element);

            }

        }

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

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

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

        

        cout << min(findMinSum(a,b),findMinSum(c,b)) <<endl;

    }

    return 0;

}
Problem: 2049B - pspspsps
Language: c++17 

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

using namespace std;

const int N=6000;

char a[N];

int main()

{

	int T;

	cin>>T;

	while(T--)

	{

		int n;

		cin>>n;

		int b1=0,b2=0;

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

		{

			cin>>a[i];

			if(i==1 or i==n)continue;

			if(a[i]=='p')b1++;

			if(a[i]=='s')b2++;

		}

		if(b1>0 and b2>0)cout<<"NO"<<endl;

		else if(b1==b2 and (a[1]!='p' or a[n]!='s'))cout<<"YES"<<endl;

		else if(b2>0 and a[1]!='p')cout<<"YES"<<endl;

		else if(b1>0 and a[n]!='s')cout<<"YES"<<endl;

		else cout<<"NO"<<endl;

		

	}

} 

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

using namespace std;

int n;

char s[505];

void solve(){

    cin>>n;

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

    	cin>>s[i];

	}

	int a=0,b=0;

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

		if(s[i]=='s')a++;

		if(s[i]=='p')b++;

	}

	if(s[1]=='p'){

		if(s[n]!='s'){

			if(a==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(s[n]=='s'){

		if(s[1]!='p'){

			if(b==0)cout<<"Yes"<<endl;

			else cout<<"No"<<endl;

		}

		else cout<<"No"<<endl;

		return;

	}

	if(a==0||b==0)cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

}

int main(){

    ios::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    int TTT=1;

    cin>>TTT;

    while(TTT--)solve();

}