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

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

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define tests int t; cin >> t; while(t--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define yes cout << "YES" << '\n'
#define no cout << "NO" << '\n'
#define ll long long
#define el '\n'
void solve() {
    int n;cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++) {
        cin>>v[i];
    }
    for(int i=0;i<n-1;i++) {
        int x=min(v[i],v[i+1]);
        v[i]-=x;
        v[i+1]-=x;
    }
    if(is_sorted(v.begin(),v.end()))yes;
    else no;

    }


int main() {
    fast;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    tests {
        solve();
}
    return 0;
}


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

    int main() {
        int t, n, i, bef, aft, subs = 0;
        scanf("%d", &t);
        while (t--) {
            scanf("%d", &n);
            bool possible = true;

            scanf("%d %d", &bef, &aft);
            for (i = 2; i < n; i++) {
                subs = aft - bef;
                bef = subs;
                scanf("%d", &aft);
                if (subs > aft || subs < 0) {
                    possible = false;
                }
            }
            if (n == 2 && aft < bef)
                possible = false;
            printf("%s\n", possible ? "YES":"NO");
        }
    }
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 125 ms):
#include <bits/stdc++.h>
using namespace std;
int dp[1001][1001];
string a,b,c;
int solve(int i, int j) {
    int k = i + j;
    if (k >= c.length()) return 0;
    if (dp[i][j] != -1) return dp[i][j];
    dp[i][j] = 1e9;
    if (i<a.length())
        dp[i][j] = min(dp[i][j], (c[k] != a[i]) + solve(i+1,j));
    if (j<b.length())
        dp[i][j] = min(dp[i][j], (c[k] != b[j]) + solve(i,j+1));
    return dp[i][j];
}
void eval() {
    memset(dp, -1, sizeof(dp));
    cin>>a>>b>>c;
    cout<<solve(0,0)<<'\n';
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while (t--)
        eval();
}

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

//calculate (x^y)%mod
ll powm(ll x, ll y, ll mod){
    ll res = 1;
    x = x%mod;
    while(y > 0){
        if(y & 1){
            res = (res*x)%mod;
        }
        y = y>>1;
        x = (x*x)%mod;
    }
    return res;
}

//returns n^(-1)%mod
ll mod_inv(ll n, ll mod){
    return powm(n, mod-2, mod);
}

//returns nCr
ll nCr(ll n, ll r, ll mod, vector<ll>&fac){
    if(n < r) return 0;
    if(r == 0 || r == n) return 1;
    return (fac[n] * mod_inv(fac[r],mod)%mod * mod_inv(fac[n-r],mod)%mod)%mod;
}

//----------------------------------------------------------------------------------------------------------------------------------------------

void solve(){
    string a, b, c;
    cin>>a>>b>>c;
    int n = a.length(), m = b.length();
    vector<vector<int>>dp(n+1, vector<int>(m+1, 1e9));
    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        dp[i+1][0] = dp[i][0] + (c[i] != a[i]);
    }
    for(int j = 0; j < m; j++){
        dp[0][j+1] = dp[0][j] + (c[j] != b[j]);
    }
    for(int i = 1; i < n+1; i++){
        for(int j = 1; j < m+1; j++){
            dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[i+j-1]), dp[i][j-1] + (b[j-1] != c[i+j-1]));
        }
    }
    cout<<dp[n][m]<<endl;
}

//--------------------------MAIN FUNCTION---------------------------------------------------------------------------------------------------

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t; cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 187 ms):
#include <bits/stdc++.h>
#define ll long long int
#define test int t;cin>>t;while(t--)
#define mod 1000000007
 
using namespace std;
ll bpow(ll a,ll b){
    ll ans=1;
    while (b>0){if (b&1)ans=(ans*a)%mod;b/=2;a=(a*a)%mod;}
    return ans;
}
bool cmp(ll x,ll y)
{
    return x>y;
}
ll gcd(ll a, ll b)
{
    if (b == 0)return a;
    return gcd(b, a % b);
}
bool isprime(ll n)
{
    if (n <= 1)   return false;
    if (n <= 3)   return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i ==  0 || n % (i + 2) == 0)  return false;
    return true;
}

int main(){

		test{
			int n,l,r ;
			cin>>n>>l>>r;
			int a[n];
			for(int i=0;i<n;i++){
				cin>>a[i];
			}
			l--;r--;
			vector <int> left,right;
			for(int i=0;i<r+1;i++){left.push_back(a[i]);}
			for(int i=l;i<n;i++){right.push_back(a[i]);}
			sort(left.begin(),left.end());
			sort(right.begin(),right.end());
			long long int ans=0,ans2=0;
			// cout<<left.size()<<right.size()<<endl;
			for(int i=0;i<r-l+1 && i<left.size();i++){
				ans+=left[i];
			}
			for(int i=0;i<r-l+1 && i<right.size();i++){ans2+=right[i];}
			cout<<min(ans,ans2)<<endl;



		}
}

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

using namespace std;

#define ll long long

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

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

#define zero cout<<"0"

#define one cout<<"1"

#define input(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}

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

#define printmap(a) for(auto it:a){cout<<it.first<<" "<<it.second<<"\n";}

#define printvecset(a) for(auto it:a){cout << it << " ";}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



int main(){

  int t;

  cin >> t;

  while(t--){

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

    vector<int> a(n);

    

    loop(i,0,n)

      cin >> a[i];

    

    vector<int> b(r),c(n-l+1);

    loop(i,0,r)

      b[i] = a[i];

    

    int j = 0; 

    loop(i,l-1,n){

      c[j] = a[i];

      j++;

    }

    

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

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

    ll s1 = 0, s2 = 0;

    loop(i,0,r-l+1){

      s1+=b[i];

      s2+=c[i];

    }

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

  }

  return 0;

}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

// Function to compute the smallest possible value of f(a)
void solve() {
    int t; // Number of test cases
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        
        vector<long long> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        
        // Step 1: Count frequency of each element
        map<long long ,  long long> freq;
        for (int x : a) {
            freq[x]++;
        }
        
        // Step 2: Calculate the number of distinct elements
        long long distinct = freq.size();
        
        // Step 3: If no changes allowed, answer is the current distinct count
        if (k == 0) {
            cout << distinct << '\n';
            continue;
        }
        
        // Step 4: Sort frequencies in increasing order
        vector<long long> freqValues;
        for (auto& [key, value] : freq) {
            freqValues.push_back(value);
        }
        sort(freqValues.begin(), freqValues.end());
        
        // Step 5: Use k changes to reduce the number of distinct elements
        long long remainingChanges = (long long)k;
        for (int i = 0; i < freqValues.size(); ++i) {
            if (freqValues[i] <= remainingChanges) {
                remainingChanges -= freqValues[i];
                distinct--; // Successfully merged one distinct element
            } else {
                break; // No more changes can be made
            }
        }
        
        // Output the result
      if(distinct==0){
        cout<<1<<endl;
      }
      else{
        cout << distinct << '\n';
        }
    }
}

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


Solution 2 (runtime: 250 ms):
#include<bits/stdc++.h>
using namespace std;
map<int, int> t; 
priority_queue<int, vector<int>, greater<> > q;
int main()
{
	int group, n, times;
	cin >> group;
	while (group--)
	{
		t.clear();
		while (!q.empty()) q.pop();
		cin >> n >> times;
		for (int i = 0; i < n; i++)
		{
			int num;
			cin >> num;
			t[num]++;
		}
		for (auto e : t)
			q.push(e.second);
		for (int i = 0; i < times; i++)
		{
			int temp = q.top();
			q.pop();
			if (temp - 1 > 0) q.push(temp - 1);
		}
		if (q.empty())
			cout << "1\n";
		else
			cout << q.size() << "\n";
	}
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

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

int main() {
    long long int T;
    cin >> T;
    while (T--) {
        long long int n, l, r;
        cin >> n >> l >> r;

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

        // Fixing sorting issues
        if (l > 1) sort(v.begin(), v.begin() + l - 1); // Sorting from index 0 to l-2
        sort(v.begin() + l - 1, v.begin() + r);        // Sorting from l-1 to r-1
        if (r < n) sort(v.begin() + r, v.end());       // Sorting from r to n-1

        long long int sum1 = 0, sum2 = 0;

        for (long long int i = 0; i < r - l + 1; i++) {
            if(i<l-1){
                if(v[i]<v[r-1-i])sum1+=v[i];
                else sum1+=v[r-1-i];
            }
            else sum1+=v[r-1-i];

            if(r+i<n){
                if(v[r+i]<v[r-1-i])sum2+=v[r+i];
                 else sum2+=v[r-1-i];
            }
             else sum2+=v[r-1-i];
        }

        cout << min(sum1, sum2) << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int maxn=1e5+5;

int a[maxn];

priority_queue<int,vector<int>,greater<int> > q1;

priority_queue<int,vector<int>,greater<int> > q2;

int n,l,r;

int t;

ll cnt1,cnt2;

void solve(){

	while(q1.size()) q1.pop();

	while(q2.size()) q2.pop();

	cnt1=cnt2=0;

	cin >> n >> l >> r;

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

	for(int i=1;i<=r;i++) q1.push(a[i]);

	for(int i=l;i<=n;i++) q2.push(a[i]);

	for(int i=1;i<=r-l+1;i++) cnt1+=q1.top(),q1.pop();

	for(int i=1;i<=r-l+1;i++) cnt2+=q2.top(),q2.pop();

	cout << min(cnt1,cnt2) << endl;

}

int main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin >> t;

	while(t--){

		solve();

	}

	return 0;

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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i += 1)
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    label:
    while(t--)
    {
        int n;
        cin >> n;
        vector<int> arr(n);
        loop(i,0,n) cin >> arr[i];
        int dif = arr[1]-arr[0];
        if(dif < 0)
            {
                cout << "NO" << endl;
                goto label;
            }
        loop(i,2,n)
        {
            dif = arr[i]-dif;
            if(dif < 0)
            {
                cout << "NO" << endl;
                goto label;
            }
        }
        cout << "YES"<< endl;
    }
}

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

#define ll long long
#define X first
#define Y second
#define pii pair<int,int>
#define pll pair<ll,ll> 

int N;
vector<int> v;

void solve() {
    cin >> N;
    v.resize(N);
    for(int &i : v) cin >> i;

    if(v[0] > v[1]) {cout << "NO\n"; return; }
    
    // 한번 연산하면 무조건 0이 된다 i번째에 연산하면 둘중 하나는 0임
    // 그 앞은 전부 0이어야한다.
    // 앞에서부터 연산을 하면서 다 죽이고 정렬 됐는지 확인
    for(int i = 0; i < N - 1; i++) {
        int minVal = min(v[i], v[i+1]);
        v[i] -= minVal, v[i + 1] -= minVal;
    }

    for(int i = 0; i < N - 1; i++) {
        if(v[i] > v[i + 1]) { cout << "NO\n"; return; }
    }
    cout << "YES\n";
}

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

    int Tc = 1;
    cin >> Tc;
    while (Tc--) {
        solve();
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 203 ms):
#include <bits/stdc++.h>
using namespace std;
int main(){
    int tt;
    cin >> tt;
    while(tt--){
        int n, k;
        cin >> n >> k;
        vector<int>a(n);
        for(int i = 0; i <n; i++){
            cin >> a[i];
        }
        
        sort(a.begin(), a.end());
        vector<int>cantidades = {1};
        for(int i = 1; i < n; i++){
            if(a[i] == a[i - 1]) cantidades.back()++;
            else{
                cantidades.push_back(1);
            }
        }
        int ans = 1;
        sort(cantidades.begin(), cantidades.end());
        cantidades.pop_back();
        int eliminados = 0;
        for(int i = 0; i < int(cantidades.size()); i++){
            if(k >= cantidades[i]) eliminados++;
            else break;

            k = k - cantidades[i];
        }

        ans += int(cantidades.size()) - eliminados;
        cout << ans << "\n";
    }
    return 0;
}

Solution 2 (runtime: 124 ms):
#include<bits/stdc++.h>
using namespace std;
void solve(){
	int n , k;
	cin >> n >> k;
	map<int , int> mp;
	for(int i = 1 ; i <= n ; i++){
		int x;
		cin >> x;
		mp[x]++;
	}
	vector<int> a;
	for(auto k : mp){
		a.push_back(k.second); 
	}
	int i = 0 , num = a.size();
	sort(a.begin() , a.end());
	while(k > 0 && num >= 0){
		if(a[i] > k){
			break;
		}
		else{
			k -= a[i];
			num--;
			i++;
		}
	}
	if(num <= 0) num = 1;
	cout << num << endl;
}
int main(){
	ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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


void solver() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int input; cin >> input;
    while(input--) {
        int n, k; cin >> n >> k;
        map<int, int> map;
        int num;
        for(int i = 0; i < n; i++) {
            cin >> num;
            map[num]++;
        }

        vector<int> vec;
        for(auto ele: map) vec.push_back(ele.second);
        sort(vec.begin(), vec.end());

        int passes = vec.size();

        for(int i = 0; k > 0 && i < vec.size() - 1; i++) {
            int temp = min(vec[i], k);
            vec[i] -= temp;
            k -= temp;
            if(vec[i] == 0) passes--;
        }

        cout << passes << "\n";
    }
}


int main(){

    solver();

}


Solution 2 (runtime: 109 ms):
#include <bits/stdc++.h>
using namespace std;
 
#define arrdec ll n;cin >> n;ll a[n];for (ll i = 0; i < n; i++) cin >> a[i];
#define f(g, h) for (ll i = g; i < h; i++)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define py cout << "YES\n"
#define pm cout << "-1\n"
#define pn cout << "NO\n"
#define pll pair<ll, ll>

void solve() 
{
    ll n, k; cin >> n >> k;
    ll a[n]; f(0, n) cin >> a[i];
    map<ll, ll> m;
    f(0, n){
        m[a[i]]++;
    }
    vector<pair<ll, ll>> v;
    for(auto i:m){
        v.pb({i.second, i.first});
    }
    sort(v.begin(), v.end());
    // for(auto i:v){
    //     cout << i.ff << " " << v[i].ss << endl;
    // }
    int j = 0;
    for(ll i = 0; i < v.size() ; i++){
        if(k-v[i].first>=0){
            k-=v[i].first;
            v[i].first = -1;
        }
        else {j = i; break;}
    }
    ll cnt = 0;
    if(k>0 and j==v.size()-1){
        cout << 1 << endl;return;
    }
    else{
        for(ll i = 0;i<v.size();i++){
            if(v[i].first!=-1){
                cnt++;
            }
        }
    }
    if(cnt == 0) cout << 1 << endl;else
    cout << cnt << endl;

}
 
 
int main()
{
 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1;
    cin >> t;
 
    for (ll i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll>PII;
typedef unsigned long long ull;
const int N=2e3+10;

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

    int k=0;
    for(int i=32;i>=0;i--)
    {
        if(((l>>i)&1)^((r>>i)&1))
        {
            k=i;
            break;
        }
    }
    int a=((1<<k)-1)|l;
    int b=a+1;
    int c=l;
    while(c==a||c==b) c++;
    cout<<a<<" "<<b<<" "<<c<<"\n";
} 	

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

Solution 2 (runtime: 62 ms):
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <unordered_set>
#include <set>
#include <map>
#include <chrono>
 
using namespace std;
 
#define se second
#define fi first
#define pb push_back
 
#define all(v) v.begin(),v.end()
#define loop(n) for(int i = 0; i < n; i++)
#define forn(i,st, n) for (int i = st; i < int(n); i++)
#define ll long long 
#define ld long double
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define umii unordered_map<int,int,custom_hash>
#define umll unordered_map<ll,ll,custom_hash>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define mem(a,b) memset(a, b, sizeof(a))
 
#define lz(x) __builtin_clz(x) // gives no. of leading zeros
#define tz(x) __builtin_ctz(x)
#define popc(x) __builtin_popcount(x)
#define setbits(x) __builtin_popcountll(x)
#define msb(x) 63 - __builtin_clzll(x)
#define lsb(x) __builtin_ctzll(x)
#define parity(x) __builtin_parity(x) // return 1 if odd no. of setbits else 0
 
#define input(v) for(auto &it:v)cin>>it 
#define output(v) for(auto &it:v)cout<<it<<" "
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
//-------------------------------------- Start_Here ------------------------------------------------------------------------------------------------

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

    ll a, b,c;

    ll m = lz(l ^ r);

    int k = 31 - m;

    a = r & ~((1LL<<k)-1);
    b = a-1;

    for(int i = l;i<=r;i++){
        if(i!= a && i!=b){
            c =i;
            break;
        }
    }
    //cout << ((1LL<<(m+1) - 1)<<" dfd ";


    
  cout<<a<<" " <<b<<" "<<c<<endl;
}
 
int main() {
    fast;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    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;
        int arr[n];
        for(int i=0;i<n;i++){
            cin >> arr[i];
        }
        int a[r];
        for(int i=0;i<r;i++){
            a[i]=arr[i];
        }
        int b[n-l+1];
        for(int i=0;i<n-l+1;i++){
            b[i]=arr[i+l-1];
        }
        
        
        
        sort(a,a+r);
        sort(b,b+n-l+1);
       
        
        long long x=0;
        long long y=0;
        for(int i=0;i<r-l+1;i++){
            x+=a[i];
            y+=b[i];
        }
        long long z=min(x,y);
        cout << z << endl;
    }
}

Solution 2 (runtime: 78 ms):
#include <cstdio>
#include <bits/stdc++.h>
 
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long,long> pll;
 
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<long long>
#define mii map<int, int>
 
#define f(i,s,e) for(long long int i=s;i<e;i++)
#define cf(i,s,e) for(long long int i=s;i<=e;i++)
#define rf(i,e,s) for(long long int i=e-1;i>=s;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.14159265358979323846

ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }

void solve() {
  int n, l, r; cin >> n >> l >> r;
  l--; r--;
  vll a(n); f(i, 0, n) cin >> a[i];
  vll x, y;
  cf(i, 0, r) x.pb(a[i]);
  f(i, l, n) y.pb(a[i]);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  int sz = r - l + 1;
  ll sm1 = accumulate(x.begin(), x.begin() + sz, 0LL);
  ll sm2 = accumulate(y.begin(), y.begin() + sz, 0LL);
  cout << min(sm1, sm2) << "\n";
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1; 
  cin >> t;
  while (t--) solve();
  return 0;
}
Problem: 2049B - pspspsps
Language: c++17 

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

#include<string>

using namespace std;

void solve()

{

	int n,jump=1;

	string s;

	cin>>n>>s;

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

	{

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

		{

			jump++;

			continue;

		}

		if(s[i]=='s'&&s[i-jump]=='p')

		{

			cout<<"NO"<<endl;

			return;

		}

		if(s[i]=='p'&&s[i-jump]=='s'&&i!=n-1&&i-jump!=0)

		{

			cout<<"NO"<<endl;

			return;

		}

		jump=1;

	}

	cout<<"YES"<<endl;

}

int main()

{

	ios::sync_with_stdio(false);

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

	int t;

	cin>>t;

	while(t--)

	{

		solve();

	}

	return 0; 

} 

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

using namespace std;





using ll = long long;

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



// #define ONLINE_JUDGE

// #ifdef ONLINE_JUDGE

// #include "debug.h"

// #endif







void solve() {

    int n ; string s;

    cin >> n >> s;



    string res[] = {"NO\n", "YES\n"};



    int S = -1 , P = -1 ;



    if(s.back() == 'p') s[n-1] = '.' ;

    if(s[0] == 's') s[0] = '.' ;



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

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

        else if (s[i] == 'p') P = i ;



        if(S!= -1 && P != -1 && S>P){//ps

            cout << res[0] ;

            return;

       }

    }

    cout << res[(S == -1 or P == -1)] ;

}







int main()

{

    int t = 1;

    cin >> t;

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

    {

        solve();

    }



}