ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<iostream>
#include<cstring>
using namespace std;
using i64 = long long;
const int N = 1e3 + 5, inf = 1e9;
int n, m, k, f[N][N];
char a[N], b[N], c[N << 1];
int solve()
{
	cin >> a >> b >> c, n = strlen(a), m = strlen(b), k = n + m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			f[i][j] = inf;
	for (int i = k; i; --i) c[i] = c[i - 1];
	for (int i = m; i; --i) b[i] = b[i - 1];
	for (int i = n; i; --i) a[i] = a[i - 1];
	for (int i = 1; i <= n; ++i) f[i][0] = f[i - 1][0] + (a[i] != c[i]);
	for (int i = 1; i <= m; ++i) f[0][i] = f[0][i - 1] + (b[i] != c[i]);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			f[i][j] = min(f[i - 1][j] + (a[i] != c[i + j]), f[i][j - 1] + (b[j] != c[i + j]));//, cout << b[j] << ' ' << c[i + j] << '\n';
	//for (int i = 0; i <= n; ++i, cout << '\n') for (int j = 0; j <= m; ++j) cout << f[i][j] << ' ';
	return f[n][m];
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T = 1; cin >> T;
	while (T--) cout << solve() << '\n';
	return 0;
}

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

using namespace std;



int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        char a[2010];

        char b[2010];

        char c[2010];

        scanf("%s", a + 1);

        scanf("%s", b + 1);

        scanf("%s", c + 1);

        int n = strlen(a + 1);

        int l = strlen(b + 1);

        vector<vector<int>> dp(n + 5, vector<int>(l + 5, n + l + 5));

        dp[0][0] = 0;

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

        {

            for (int j = 0; j <= l; j++)

            {

                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (a[i + 1] != c[i + j + 1]));

                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (b[j + 1] != c[i + j + 1]));

            }

        }

        cout << dp[n][l] << endl;

    }

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

Solution 1 (runtime: 328 ms):
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int a[maxn];
int main(){
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		for(int i = 0; i < n; i++)
			cin >> a[i];
			
		int ind = 0;
		bool flag = 0;
//		if(n == 2 && a[0] > a[1]){
//			cout << "NO\n";
//			continue;
//		}
		while(ind <= n - 2){
			if(a[ind] > a[ind+1]){
				flag = 1;
				break;
			}
			a[ind+1] -= a[ind];
			a[ind] = 0;
			ind += 1;
		}
		if(flag)
			cout << "NO\n";
		else
			cout << "YES\n";
		
	
	}
}

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

using namespace std;

 

#define I ios_base::sync_with_stdio(false);

#define want cin.tie(NULL);

#define sex cout.tie(NULL);

#define ll long long

#define endl '\n'

#define ulli unsigned long long int

#define read(x) ll x;cin>>x;



int main()

{

    I want sex

    read(t)

    while(t--)

    {

        read(len)

        vector<ll> a(len);

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

        cin>>a[i];

        ll flag=1;

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

        {

            ll mini=min(a[i],a[i+1]);

            a[i]-=mini;

            a[i+1]-=mini;

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

            flag=0;

        }

        if(flag)

        cout<<"YES"<<endl;

        else

        cout<<"NO"<<endl;

    }

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

Solution 1 (runtime: 46 ms):
/*
*   author: bobbyCodes
*/

#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/treepolicy.hpp>
//#define pbds tree<ll , null_type, less , rb_tree_tag, tree_order_static_node_update> 
#define ll long long
#define pb push_back
#define IM INT_MAX
#define IN INT_MIN
#define fo for(int i=0;i<n;i++){}
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
/* -------------------------------------------------------------------------------------------------------------
//ll gcd(ll a,ll b){for(ll i = min(a,b);i >=1;i--){if(!(a%i) && !(b%i)){return i;}}return 1;}
ll seiveOfErytosthesis(ll k,ll n = 1e6){vector<bool> v(n+1,true);v[0]=v[1]=false;for(ll i =2; i*i<= n; i++){for(ll j =2*i; j <=n ; j+=i){if(v[j]){v[j]=false;}}}ll num=0;for(ll i=k; i<=1e6;i++){if(v[i]){num= i;break;}}return num;}
-------------------------------------------------------------------------------------------------------------
*/
//using namespace __gnu_pbds

void init_code(){
    fast_io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
}
void solve(){
   int n;
   cin>>n;

   vector<ll>v(n);

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

   int now=n;

   long long ans= -1e18;

   for(int i=0; i<n ;i ++){
      long long sum=0;
      for(int j=0; j< now; j++ ){
         sum+=v[j];
      }
      if(i==0){
         ans=max(ans,sum);
      }else{
         ans=max(ans, max(sum,(-sum)));
      }
      for(int j=0; j<now-1; j++){
         v[j]=v[j+1] - v[j];
      }
      now--;
   }
   cout<<ans<<endl;
}
int main() {
   init_code();
   int t = 1; cin >> t;
   while(t--){
         solve();
   }
   return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll dim=(1e6+7);
const ll inf=1e10+77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>
ll mn, n, cm, b, sat, pr[dim], c,  k, m, l, r, g, t;
ll vis[dim];
//string t;
string s;
ll dp[dim], a[dim];


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, k;
    cin>>t;
    while(t--){
        cin>>n;
        vll tmp, cur;
        ll sum;
        sum=0;
        ll mx=-inf;
        for(int i=1; i<=n; i++){
            cin>>x;
            tmp.push_back(x);
            sum+=x;
        }
        mx=sum;
        for(int i=1; i<n; i++){
            sum=0;
            for(int i=0; i+1<tmp.size(); i++){
                cur.push_back(tmp[i+1]-tmp[i]);
                sum+=tmp[i+1]-tmp[i];
            }
            if(sum<0 ){
               for(int j=0; j<n-i; j++){
                cur[j]=-cur[j];
               }

                sum=-sum;
            }

            mx=max(mx, sum);

            tmp=cur;
            cur.clear();
        }
        cout<<mx<<endl;

    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include<climits>
#include <queue>
#include<stack>
#include<cmath>
using namespace std;
void go(string& ss);
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--) {
		string ss;
		cin >> ss;
		go(ss);
	}

	return 0;
}

void go(string& ss) {
	int length = ss.length();
	for (int ind = 0;ind < length;ind++) {
		for (int r = ind + 1;r <= ind + 9 and r < length;r++) {
			if ((int)ss[r] - (int)ss[ind] > r - ind) {
				char temp = ss[r];
				for (int i = r;i > ind;i--) {
					swap(ss[i], ss[i - 1]);
				}
				ss[ind] = (char)((int)temp - (r - ind));
			}
		}
	}
	cout << ss << endl;
}


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

using namespace std;

using dqi = deque<int>;
using vi = vector<int>;
using mii = unordered_map<int, int>;
using mip = unordered_map<int, pair<int, int>>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using spii = set<pair<int, int>>;
using ll = long long;

void solve()
{
    string num;
    cin >> num;

    for (int i = 0; i < num.size(); i++)
    {
        int max = 0;
        int ind = 0;
        for (int j = i + 1; j < min(i + 10, (int)num.size()); j++)
        {
            if (num[j] == '0')
                continue;
            int nn = num[j] - '0' - j + i;
            if (nn > max && nn > (num[i] - '0'))
            {
                max = nn;
                ind = j;
            }
        }
        if (max > 0)
        {
            while (ind > i)
            {
                swap(num[ind], num[ind - 1]);
                ind--;
            }
            num[i] = char(max + '0');
        }
    }
    cout << num << endl;
}

int main()
{
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        solve();

    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 233 ms):
// Problem: B. Gorilla and the Exam
// Contest: Codeforces - Hello 2025
// URL: https://codeforces.com/problemset/problem/2057/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>

using namespace std;

int main(){
	int t;
	cin >> t;
	while(t--){
		int n, k;
		cin >> n >> k;
		int ar[n];
		vector<int> f;
		for(int &x : ar){
			cin >> x;
		}
		sort(ar , ar + n);
		int cnt = 0, value = -1;
		for(int i = 0;i < n;i++){
			int x = ar[i];
			if (value != x){
				if(value != -1) f.push_back(cnt);
				value = x;
				cnt = 1;
			}else cnt++;
			if(i+1==n)f.push_back(cnt);
		}
		sort(f.begin(),f.end());
		int ans = 0;
		for(int i = 0;i*1ULL < f.size();i++){
			if(k >= f[i]){
				k-=f[i];
				ans++;
			}else break;
		}
		int bruh = f.size() - ans;
		cout << max(1, bruh) << endl;
	}
}
//3 2 1 4 4 3 4 2 1 3 3
//1 1 2 2 3 3 3 3 4 4 4 - 4 distinct

Solution 2 (runtime: 234 ms):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;

bool cmp(PII &a, PII &b)
{
    return a.second < b.second;
}

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n, k;
        cin >> n >> k;
        map<int, int> _map;
        for (int i = 1; i <= n; i++)
        {
            int key;
            cin >> key;
            _map[key]++;
        }
        vector<PII> vec(_map.begin(), _map.end());
        sort(vec.begin(), vec.end(), cmp);
        int sum = vec[0].second, step = vec.size(), index = 1;
        while (sum <= k && step > 1)
        {
            step--;
            sum += vec[index++].second;
        }
        cout << step << endl;
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
const int inf=1e9;
int main(){
	int t;
	cin>>t;
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int m=(int)a.size(),n=(int)b.size();
		int dp[m+1][n+1];
	    fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
		dp[0][0]=0;
		for(int i=0;i<m;i++){
		 dp[i+1][0]=dp[i][0]+(a[i]!=c[i]);
		}
		for(int i=0;i<n;i++){
		 dp[0][i+1]=dp[0][i]+(b[i]!=c[i]);
		}
		for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++){
		dp[i][j]=min(dp[i][j-1]+(b[j-1]!=c[i+j-1]),dp[i-1][j]+(a[i-1]!=c[i+j-1]));
		}
		cout<<dp[m][n]<<endl;
	}
	return 0;
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define MOD 998244353
#define print(a) for(auto x : a) cerr << x << " "; cerr<<endl;
#define print1(b) for(auto x : b) cerr << x.first << " " << x.second <<endl;
#define print2(a,x,y) for(int i =x ;i<y;i++) cerr<< a[i] << " ";cerr<<endl;
#define F first
#define S second
#define bug(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char * name , Arg1&& arg1){cerr << name << " : " << arg1 << endl ; }
template <typename Arg1, typename... Args>
void __f(const char * names , Arg1&& arg1, Args&&... args){
    const char* comma = strchr (names + 1,',');
    cerr.write (names, comma - names) << " : " << arg1 << " | ";__f(comma +1, args... );
}


int32_t main() {
    std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr); std::cout.tie(nullptr);
    int ttt=1 ;
    cin>>ttt;
    for(int tt = 1 ; tt <= ttt ; tt++ ){
        string s1 , s2 , s3;
        cin >> s1 >> s2 >> s3;
        int n = s1.length() , m = s2.length();
        vector<vector<int>> dp(n + 1 , vector <int> (m + 1 , -1));
        // cout << f(0 , 0 , s1 , s2 , s3 , dp) << '\n';
        for(int i = n ; i >= 0 ; i--){
            for(int j = m ; j >= 0 ; j--){
                if(i == n && j == m)dp[i][j] = 0;
                else{
                    int ans = 1e9;
                    if(i < n){
                        if(s3[i + j] == s1[i])ans = min(ans , dp[i+1][j]);
                        else ans = min(ans , 1 + dp[i+1][j]);
                    }
                    if(j < m){
                        if(s3[i + j] == s2[j])ans = min(ans , dp[i][j+1]);
                        else ans = min(ans , 1 + dp[i][j+1]);
                    }
                    dp[i][j] = ans;
                }
            }
        }
        cout << dp[0][0] << '\n';
    }  
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

using namespace std;

void solve()

{

    int n;

    cin>>n;

    vector<int> a(n);

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

    int j=0;

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

    {

        if(a[i-1]>a[i]) j=i;

    }

    if(j==0)

    {

        cout<<"YES"<<'\n';

        return ;

    }

    auto jian = [&](int l)

    {

        int minn=min(a[l],a[l+1]);

        a[l]-=minn;

        a[l+1]-=minn;

    };

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

    {

        jian(i);

    }

    if(is_sorted(a.begin(),a.end()))

    {

        cout<<"YES"<<"\n";

        return ;

    }

    else cout<<"NO"<<'\n';

}

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: 328 ms):
#include <iostream>

#include <vector>

#include <cmath>

using namespace std;



void ans()

{

int n;

cin >> n;

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

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

{

cin >> v[i];

}

bool stat = true;

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

{

int m = min(v[i], v[i + 1]);

v[i] -= m;

v[i + 1] -= m;

if (v[i] != 0)

{

stat = false;

break;

}

}



if (stat)

cout << "YES" << endl;

else

cout << "NO" << endl;

}



int main()

{

int t;

cin >> t;

while (t--)

{

ans();

}

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

Solution 1 (runtime: 92 ms):
#include <iostream>
#include <string>
using namespace std;

bool isDivisibleBy9(const string& n) {
    int sum = 0, count2 = 0, count3 = 0;

    // Calculate the sum of digits and count '2's and '3's
    for (char c : n) {
        int digit = c - '0';
        sum += digit;
        if (digit == 2) count2++;
        if (digit == 3) count3++;
    }

    if (sum % 9 == 0) return true;

    // Try replacing some '2's with '4's and '3's with '9's
    for (int i = 0; i <= count2; i++) {
        for (int j = 0; j <= count3; j++) {
            int adjustedSum = sum + i * (4 - 2) + j * (9 - 3);
            if (adjustedSum % 9 == 0) {
                return true;
            }
        }
    }

    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string n;
        cin >> n;
        if (isDivisibleBy9(n)) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}


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

using namespace std;

#define ll long long

const int MOD = 1000000007;



bool solve(string &str, ll sum, int ind, vector<vector<int>>& dp) {

  

    if (ind < 0) return sum % 9 == 0;

    if (sum % 9 == 0) return true;

    

   

    if (dp[ind][sum % 9] != -1) return dp[ind][sum % 9];

    

   

    bool not_pick = solve(str, sum, ind - 1, dp);

    

   

    bool pick = false;

    if (str[ind] - '0' <= 3) {

        ll new_sum = sum - (str[ind] - '0') + (str[ind] - '0') * (str[ind] - '0');

        pick = solve(str, new_sum, ind - 1, dp);

    }

    

   

    return dp[ind][sum % 9] = pick || not_pick;

}



int main() {

    ll t;

    cin >> t;

    while (t--) {

        string str;

        cin >> str;

        int n = str.length();

        ll sum = 0;

        

       

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

            sum += str[i] - '0';

        }

        

       

        vector<vector<int>> dp(n, vector<int>(9, -1));

        

        

        bool ans = solve(str, sum, n - 1, dp);

        

       

        if (ans) {

            cout << "YES" << endl;

        } else {

            cout << "NO" << endl;

        }

    }

    return 0;

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

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


int main(){
    int t;
    cin>>t;
    while(t--){
        int n,l,r;
        cin>>n>>l>>r;
        l--;
        r--;
        vector<ll> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }

        vector<ll> lft;
        vector<ll> rht;
        
       for(int i=0;i<=r;i++){
        lft.push_back(a[i]);
       }
       
       for(int i=l;i<n;i++){
        rht.push_back(a[i]);
       }

       sort(lft.begin(),lft.end());
       sort(rht.begin(),rht.end());
       ll suml=0,sumr=0;
       for(int i=0;i<(r-l+1);i++){
         suml+=lft[i];
         sumr+=rht[i];
       }

       ll sum=min(suml,sumr);
       cout<<sum<<endl;
    }
}

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

using namespace std;

#define int long long

#define INF __builtin_inf()

#define endl '\n'

#define couthi cout <<'h'<<'i'<<endl;

#define hi(i) cout <<'h'<<'i'<<i<<endl;

#define vin(a) for(auto&XX:a)cin>>XX;

#define vout(v) for (auto XX: v)cout<<XX<<' ';cout<<endl;

#define ignore_kroo_ise ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);

// ░░░░░░░░░░░░░▄▄▄▄▄▄▄░░░░░░░░░

// ░░░░░░░░░▄▀▀▀░░░░░░░▀▄░░░░░░░

// ░░░░░░░▄▀░░░░░░░░░░░░▀▄░░░░░░

// ░░░░░░▄▀░░░░░░░░░░▄▀▀▄▀▄░░░░░

// ░░░░▄▀░░░░░░░░░░▄▀░░██▄▀▄░░░░

// ░░░▄▀░░▄▀▀▀▄░░░░█░░░▀▀░█▀▄░░░

// ░░░█░░█▄░░░░█░░░▀▄░░░░░▐░█░░░

// ░░▐▌░░█▀░░░▄▀░░░░░▀▄▄▄▄▀░░█░░

// ░░▐▌░░█░░░▄▀░░░░░░░░░░░░░░█░░

// ░░▐▌░░░▀▀▀░░░░░░░░░░░░░░░░▐▌░

// ░░▐▌░░░░░░░░░░░░░░░▄░░░░░░▐▌░

// ░░▐▌░░░░░░░░░▄░░░░░█░░░░░░▐▌░

// ░░░█░░░░░░░░░▀█▄░░▄█░░░░░░▐▌░

// ░░░▐▌░░░░░░░░░░▀▀▀▀░░░░░░░▐▌░

// ░░░░█░░░░░░░░░░░░░░░░░░░░░█░░

// ░░░░▐▌▀▄░░░░░░░░░░░░░░░░░▐▌░░

// ░░░░░█░░▀░░░░░░░░░░░░░░░░▀░░░

// ╦═╗╔═╗╔══║░║╔═╗░░╦═╗╦░╦═╗░░╦░

// ║░║╠═╣╠═░║░║║░║░░║░║║░║░║░░║░

// ╩═╝║░║║░░╚═╝╩╩╝░░╩═╝╩░╩═╝░░╩░

// ═╦║░║╔═╗═╦═░░╔═╗╔═╗╔═╗╦═╗░╔═╗

// ░║║░║╚═╗░║░░░╠╦╝╠╣░╠═╣║░║░░╔╝

// ╚╝╚═╝╚═╝░║░░░║╚═╚═╝║░║╩═╝░░▄░



//?-------------------------------------------------------------------------------------------------

void solve() {

    int n,l,r;

    cin >> n >> l >> r;

    vector<int> v(n);

    vin(v);

    vector<int> a(n-l+1);

    vector<int> b(r);

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

        {

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

        }

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

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

        {

            b[i]=v[i];

        }

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

    int ans1=0;

    int ans2=0;

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

        {

            ans1+=a[i];

        }

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

        {

            ans2+=b[i];

        }

    cout << min(ans1,ans2) << endl;

}



int32_t main()

{

    ignore_kroo_ise

    int t = 1;

    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;

void sol(){
     int n; cin >> n;
     vector<int> a(n);

     for (int i = 0; i < n; i++) cin >> a[i];
     for (int i = 0; i < n-1; i++){
          int mn = min(a[i], a[i+1]);
          a[i] -= mn;
          a[i+1] -= mn;
     }
     for (int i = 0; i < n-1; i++){
          if (a[i+1] < a[i]){
               cout << "NO\n";
               return;
          }
     }
     cout << "YES\n";

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  
  int t;cin >> t;
  while (t--) sol();
  return 0;
}

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



using namespace std;



int n, a[200010];



void solve() {

    cin >> n;

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

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

        int t = a[i] - min(a[i], a[i + 1]);

        if (i > 1 && max(a[i], t) < a[i - 1]) {

            cout << "NO\n";

            return;

        }

        if (i == 1 || (i > 1 && t >= a[i - 1])) {

            a[i + 1] -= min(a[i], a[i + 1]);

            a[i] = t;

        }

    }

    if (a[n] < a[n - 1]) cout << "NO\n";

    else cout << "YES\n";

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int tcs;

    cin >> tcs;

    while(tcs--) solve();

    

    return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

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

#define ll long long
#define vi vector<int>
#define f(i, s, e) for (long long int i = s; i < e; i++)

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    int t;
    cin >> t;

    while (t--) {
        string s;
        cin >> s;
        ll n = s.length();
        vi ans;

        
        f(i, 0, n) {
            ll mx = INT_MIN, mx_index = -1;
        
            ll limit = min(i + 9, n - 1);

          
            f(j, i, limit + 1) {
                ll value = s[j] - '0' - (j-i);
                if (value > mx) {
                    mx = value;
                    mx_index = j;
                }
            }


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

          
            mx_index--;  
        }
        s[i]=char(mx +'0');
        }

       cout<<s;
       cout<<"\n";
    }
    return 0;
}


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

#define ll long long

using namespace std;



void solve() {

string s;

cin >> s;

ll n=s.length();

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

ll c=s[i]-'0';

ll indx=i;

for(ll j=i;j<min(i+10,n);j++){

if((s[j]-'0'-(j-i))>c){

c=s[j]-'0'-(j-i);

indx=j;

}



}

while(indx>i){

swap(s[indx],s[indx-1]);

indx--;

}

s[i]=char(c+'0');

}

cout<<s<<endl;





}



int main() {

ll t;

cin >> t;

while (t--) {

solve();

}

return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 61 ms):
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);

    int t;
    string s;
    cin>>t;

    string ans[t];

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

        for(int j=0;j<s.length()-1;j++) {
            int mini = 0;
            int len = s.length();
            int condition = min(9,len-j);

            for(int k=1;k<condition;k++) {
                if(s[j+k] - k > s[j+mini] - mini) {
                    mini = k;
                }
            }

            for(int k=mini;k>0;k--) {
                swap(s[j+k-1],s[j+k]);
                s[j+k-1] -= 1;
            }
        }

        ans[i] = s;
    }

    for(int i=0;i<t;i++) {
        cout<<ans[i]<<endl;
    }

    return 0;
}

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

#include<vector>

#include<string>

int main(){

    int t{};

    std::cin>>t;

    std::string s;

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

        std::cin>>s;

        int len=s.size();

        for(int y=1;y<len;y++){

            int curr{y-1};

            int ind{-1};

            int dig{s[y]-1};

            while(dig>0 && curr>=0){

                if(dig>s[curr]){

                    ind=curr;

                }

                dig--;

                curr--;

            }

            if(ind !=-1){

                int tmp= s[y]-(y-ind);

                int tmp2{};

                for(int z=ind;z<=y;z++){

                    tmp2= s[z];

                    s[z]=tmp;

                    tmp=tmp2;

                }

            }

        }

        std::cout<<s<<'\n';

    }

    return 0;

}