ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: c++17 

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

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    vector<long long>arr(n);
    long long sum = 0;
    for(int i=0; i<n; i++){
    cin>>arr[i];
    sum += arr[i];
    }
    long long val = n , maxi = sum;
    while(val>1){
    vector<long long>temp;
    long long sum = 0;
    for(int i=1; i<arr.size(); i++){
    temp.push_back(arr[i]-arr[i-1]);
    sum += (arr[i]-arr[i-1]);
    }
    arr = temp;
    val--;
    maxi = max(maxi , abs(sum));
    }
    cout<<maxi<<endl;
    }
}


Solution 2 (runtime: 62 ms):
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;

const int N = 55;
ll a[N];
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	ll ans = 0;
	if (n == 1) {
		cout << a[1] << endl;
		return;
	}
	while (n > 1) {
		ll res = 0;
		for (int i = 1; i <= n; ++i) {
			res += a[i];
		}
		ans = max(res, ans);
		res = 0;
		for (int i = 1; i < n; ++i) {
			a[i] = a[i + 1] - a[i];
			res += a[i];
		}
		ans = max(abs(res), ans);
		n--;
	}
	cout << ans << endl;
	return;
}

int main() {
	int t;
	cin >> t;
	while (t--)solve();
	return 0;
}
Problem: 2050D - Digital string maximization
Language: c++17 

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

using namespace std;

#define endl '\n' 

#define int long long int



int num(char ch) {

    return ch - '0';

}



void swap_array(int start, int end, string &s) {

    for (int i=end;i>start;i--) {

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

    }

}



void solve(){

    string s; cin>>s;

    int n=s.length();

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

        int end=-1,maxi=num(s[i]);

        int j=i+1;

        while (j<n&&j-i<=9) {

            if(s[j]=='0') {j++;continue;}

            if (num(s[j])-(j-i)>maxi) {

                maxi=num(s[j])-(j-i);

                end=j;

            }

            j++;

        }

        if(end!=-1){ 

            swap_array(i,end,s);

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

        }

    }

    cout<<s<<endl;

}



int32_t main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin >> t;

    while(t--)

        solve();

    return 0;

}





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

using namespace std;

#define int long long

#define endl '\n'



signed main(){

int t;

cin>>t;

//t=1;

while (t--)

{

string s;

cin>>s;

int n = s.size();





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

{

vector<pair<int,int>> v;

int temp = s[i] - '0';

for (int j = i+1; j < min(i+9,n); j++)

{

v.push_back({s[j]-'0'-(j-i),j});

}

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

if (!v.empty())

{

if (v.back().first>temp)

{



int check = v.back().first;

int ind = -1;

for (int j = 0; j < v.size(); j++)

{

if (v[j].first==check)

{

ind = v[j].second;

break;

}



}

s[ind] = '0' + check;



for (int j = ind; j>i; j--)

{

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

}



}



}





}

cout << s << endl;



}



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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
void solve() {
    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;
}
int main() {
    int TESTS; cin>>TESTS;
    while(TESTS--){
        solve();
        cout<<'\n';
    }
    return 0;
}

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

#include <cmath>

#include <stack>

#include <string>

#include <algorithm>

#include <set>

#include <vector>

#include <deque>

#include <iterator>

#include <queue>

using namespace std;

#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define endl '\n'



//g++ -o junior junior.cpp -g

typedef set<int>::iterator Iterator;

typedef string::iterator Iterator2;

void solve()

{

    string fullNum;

    std::cin>>fullNum;

    //Iterator2 i = fullNum.begin();

    string result = "";

    while (!fullNum.empty())

    {

        int posBig=0;

        int difference=0;

        for (int i = 1; i < fullNum.size() && i < 10; i++)

        {

            if(fullNum[i]-fullNum[0]-i > difference ){

                difference=fullNum[i]-fullNum[0]-i;

                posBig=i;

            }

        }

        result.push_back(fullNum[posBig]-posBig);

        fullNum.erase(fullNum.begin()+posBig);

    }

    std::cout<<result;

}

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

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

int main()

{

    Fast;

    int test;

    std::cin>>test;    

    while (test--)

    {

        solve();

        std::cout<<endl;   

    } 

    return 0;

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

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

using namespace std;

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

    while (t--) {
        int n;
        cin >> n;

        vector<int> a(n);
        for (auto& val: a) cin >> val;

        bool ok = true;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] < 0) {
                ok = false;
                break;
            }

            if (a[i]) {
                a[i + 1] -= a[i];
                a[i] = 0;
            }
        }
        cout << ((ok && a.back() >= 0) ? "YES" : "NO") << "\n";
    }
    return 0;
}


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

#include <cmath>

using namespace std;



int main() {

    int t;

    cin >> t;

    while (t--){

    int n;

    cin>>n;

    int a[n];

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

    int count=1;

    int i = 0;

    while (i<n-1){

        if (a[i]>a[i+1]){count=0; break;}

        else{a[i+1]=a[i+1]-a[i]; a[i]=a[i]-a[i];i++;} 

    }

    if(count==0)cout<<"NO"<<endl;

    else cout<< "YES"<<endl;

    }

    return 0;

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

Solution 1 (runtime: 202 ms):
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
    int t; cin >> t;
    for (int i = 0; i < t; i++) {
        ll n, l, r; cin >> n >> l >> r;
        l--; r--;
        vector<ll> a(n);
        for (int j = 0; j < n; j++) {
            cin >> a[j];
        }
        vector<ll> pre, tar, suf;
        pre.assign(a.begin(), a.begin() + l);
        tar.assign(a.begin() + l, a.begin() + r + 1);
        suf.assign(a.begin() + r + 1, a.end());
        sort(pre.begin(), pre.end());
        sort(tar.begin(), tar.end(), greater<int>());
        sort(suf.begin(), suf.end());
        // Deal with pre
        ll preSum = 0, sufSum = 0;
        for (int j = 0; j < tar.size(); j++) {
            if (j < pre.size() && pre[j] < tar[j]) {
                preSum += pre[j];
            }
            else {
                preSum += tar[j];
            }
        }
        // Deal with suf
        for (int j = 0; j < tar.size(); j++) {
            if (j < suf.size() && suf[j] < tar[j]) {
                sufSum += suf[j];
            }
            else {
                sufSum += tar[j];
            }
        }
        cout << min(preSum, sufSum) << endl;
    }
    return 0;
}

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

#include <vector>

#include <set>

#include <algorithm>

#include <unordered_map>

#include <math.h>

using namespace std;



#define ll long long

#define vi vector<int>

#define vll vector<ll>

#define vvi vector<vi>

#define vb vector<bool>

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

string yon[] = {"NO", "YES"};



int main() {

    int t;

    cin >> t;

    while (t--) {

        int n, l,r;

        cin>> n>> l>> r;

        int len = r-l+1;

        vi v(n);

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

        vi v1(r), v2 (n-l+1);

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

            if(i<r) v1[i] = v[i];

            if(i>=l-1) v2[i-l+1] = v[i];

        }

        sort(all(v1));

        sort(all(v2));

        ll sm1= 0, sm2=0;

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

            sm1+= v1[i];

            sm2+= v2[i];

        }







        cout<< min(sm1, sm2)<<"\n";

    }

    return 0;

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

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

#define REP(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
typedef vector<int> vi;

void solve(){
    int n;
    cin>>n;
    vi num(n);
    REP(i,0,n) cin >> num[i];
    
    REP(i,0,n-1){
        int minN = min(num[i], num[i+1]);
        num[i] -= minN;
        num[i+1] -= minN;
    }

    cout << (is_sorted(num.begin(), num.end()) ? "YES" : "NO") << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

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

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

#define ll long long
#define int long long
#define ci05 codeInterpreter05
#define v32 vector<int>

void solve() {
    int n; cin >> n;

    v32 a(n);
    for(auto &i: a) cin >> i;

    for(int i = 1; i < n; i++){
        if(a[i] >= a[i - 1]){
            a[i] -= a[i - 1];
            a[i - 1] = 0;
        }
    }

    for(int i = 1; i < n; i++){
        if(a[i] < a[i - 1]){
            cout << "NO" << endl;
            return;
        }
    }

    cout << "YES" << endl;
}

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

    int t;
    cin >> t;
    while (t--) solve();
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <iostream>
using namespace std;
int dp[1005][1005];
int T;
int main(){
	cin >> T;
	for(int i=1;i<=T;i++){
		string a,b,c;
		cin>>a>>b>>c;
		for (int j=0;j<=(int)a.size();j++){
			for (int k=0;k<=(int)b.size();k++){
				dp[j][k]=0;
			}
		}
		for (int j=0;j<=(int)a.size();j++){
			for (int k=0;k<=(int)b.size();k++){
					if (j==0&&k==0){
						continue;
					}
					else if (j==0){
						dp[j][k]=dp[j][k-1]+(b[k-1]!=c[k-1]);
					} 
					else if (k==0){
						dp[j][k]=dp[j-1][k]+(a[j-1]!=c[j-1]);
					} 
					else{
						dp[j][k]=min(dp[j-1][k]+(a[j-1]!=c[j+k-1]),dp[j][k-1]+(b[k-1]!=c[j+k-1]));
					}
				}
		}
		cout << dp[a.size()][b.size()] << "\n";
	}
	return 0;	
}

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

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

using namespace std;

#define endl '\n'

#define x first

#define y second

#define int long long

typedef long long ll;

typedef long double ld;

typedef pair<int,int>PII;

typedef pair<double,double>Pdd;

typedef unsigned long long ull;

const int mod= 998244353;

const int P=131;

#define ls(u) tr[u].ls

#define rs(u) tr[u].rs

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

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

using i64 = long long;

const int INF=1e18;

constexpr i64 inf=0x3f3f3f3f3f3f3f3f;

const int N =2e5+10 ,M=5e4+10;

//int dxx[]= {-1,-1,0,1,1,1,0,-1};

//int dyy[]= {0,1,1,1,0,-1,-1,-1};

int n,m,k;

const int maxn=1e5+10;

int f[1010][1010];

void solve() {

	string a,b,c;

	cin>>a>>b>>c;

	n=a.size(),m=b.size();

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

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

			f[i][j]=0;

		}

	}

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

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

			if(i==0&&j==0)continue;

			if(i==0) {

				f[i][j]=f[i][j-1]+(b[j-1]!=c[j-1]);

			} else if(j==0) {

				f[i][j]=f[i-1][j]+(a[i-1]!=c[i-1]);

			} else {

               f[i][j]=min(f[i-1][j]+(a[i-1]!=c[i+j-1]),f[i][j-1]+(b[j-1]!=c[j+i-1]));

			}

		}

	}

	cout<<f[n][m]<<endl;

}

signed main() {

	FAST;

	int t=1;

	cin>>t;

	while (t--) solve();

	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(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int n, l, r;
        cin >> n >> l >> r;
        l--;
        r--;

        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        sort(a.begin(), a.begin() + l);
        sort(a.begin() + l, a.begin() + r + 1);
        sort(a.begin() + r + 1, a.end());
        
        long long left = 0;
        for (int i = r, j = 0; i >= l; i--, j++) {
            if (j < l) {
                left += min(a[j], a[i]);
            } else {
                left += a[i];
            }
        }
        long long right = 0;
        for (int i = r, j = r + 1; i >= l; i--, j++) {
            if (j < n) {
                right += min(a[j], a[i]);
            } else {
                right += a[i];
            }
        }
        cout << min(left, right) << "\n";
    }
    return 0;
}

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

using namespace std;

#define ll long long



ll f(vector<ll> &a, ll l, ll r, ll start, ll end)

{

    ll len = r - l + 1;

    vector<ll> values;



    for (ll i = start; i <= end; i++)

    {

        values.push_back(a[i - 1]);

    }



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



    ll sum = 0;

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

    {

        sum += values[i];

    }

    return sum;

}



int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    ll t;

    cin >> t;

    while (t--)

    {

        ll n, l, r;

        cin >> n >> l >> r;



        vector<ll> a(n);

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

        {

            cin >> a[i];

        }



        ll ans1 = f(a, l, r, 1, r);



        ll ans2 = f(a, l, r, l, n);



        cout << min(ans1, ans2) << "\n";

    }

    return 0;

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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2*1e5+10;
int t,n;

ll a[1010];
void solve()
{
	ll ans=-1e18;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int now=n;now>=1;now--)
	{
		ll sum=0;
		for(int i=1;i<=now;i++) sum+=a[i];
		if(now==n) ans=max(ans,sum);
		else ans=max(ans,max(sum,-sum));
		for(int i=1;i<now;i++) a[i]=a[i+1]-a[i];
	}
	cout<<ans<<'\n';
}

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

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

void solve(){
    int n;cin>>n;
    vector<ll> v;
    ll mx=0;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        mx+=x;
        v.push_back(x);
    }
    while(n>1){
        vector<ll> u;
        ll sum=0;
        for(int i=1;i<v.size();i++){
            ll dif=v[i]-v[i-1];
            sum+=dif;
            u.push_back(dif);
        }
        mx=max(mx,abs(sum));
        v=u;
        n--;
    }
    cout<<mx<<"\n";
}
int main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
#define int long long
int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = (x << 1) + (x << 3) + ch - '0';
        ch = getchar();
    }
    return x * f;
}

void solve()
{
    int n;
    int l, r;
    cin >> n >> l >> r;
    int len = r - l + 1;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = l; i <= r; i++)
    {
        ans += a[i];
    }
    // [1 r]
    vector<int> b;
    for (int i = 1; i <= r; i++)
    {
        b.push_back(a[i]);
    }
    sort(b.begin(), b.end());
    int t1 = 0;
    for (int i = 0; i < len; i++)
    {
        t1 += b[i];
    }
    // [ l n ]
    vector<int> c;
    for (int i = l; i <= n; i++)
    {
        c.push_back(a[i]);
    }
    sort(c.begin(), c.end());
    int t2 = 0;
    for (int i = 0; i < len; i++)
    {
        t2 += c[i];
    }
    int t = min(t1, t2);
    cout << t << "\n";
}
signed main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<pi> vpi;
typedef vector<vector<pi>> vvpi;
typedef vector<vector<vector<pi>>> vvvpi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<long double> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;

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

    int T;
    cin >> T;
    while (T--)
    {
        int N, l, r;
        cin >> N >> l >> r;
        vll v(N);
        for (auto& i : v) cin >> i;

        vll s1 = vll(v.begin(), v.begin() + r);
        vll s2 = vll(v.begin() + l - 1, v.end());
        sort(s1.begin(), s1.end());
        sort(s2.begin(), s2.end());

        ll sum1 = 0, sum2 = 0;

        for (int i = 0; i < r - l + 1; i++)
        {
            sum1 += s1[i];
            sum2 += s2[i];
        }
        
        cout << min(sum1, sum2) << '\n';
    }
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

bool canReachSum(int cnt1, int val1, int cnt2, int val2, int target) {
    for (int i = 0; i <= cnt1; i++) {
        int remaining = target - i * val1;
        if (remaining < 0) break;

        if (remaining % val2 == 0 && remaining / val2 <= cnt2) {
            return true;
        }
    }
    return false;
}

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

        int n = s.size(); // Fixed incorrect method call `string.size()` to `s.size()`

        int cnt2 = 0, cnt3 = 0, sum = 0;

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

            if (s[i] - '0' == 2) cnt2++;
            if (s[i] - '0' == 3) cnt3++;
        }

        int required = (9 - sum % 9) % 9; // Correct modular adjustment for required sum
        pair<int, int> two = {cnt2, 2};
        pair<int, int> three = {cnt3, 6};
        bool ans = false;

        while (required <= two.first * two.second + three.first * three.second) {
            if (canReachSum(two.first, two.second, three.first, three.second, required)) {
                cout << "YES" << endl;
                ans = true;
                break;
            }
            required += 9; // Increment by 9 for the next possible sum
        }

        if (!ans) {
            cout << "NO" << endl;
        }
    }

    return 0;
}


Solution 2 (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;
        int two = 0, three = 0;

        for(int i = 0; i<s.size(); i++){
            if(s[i] == '2') two++;
            else if(s[i] == '3') three++;

            sum+= s[i] - '0';
        }   
        
        if(sum%9==0){
            cout << "YES\n";
            continue;
        }

        vector <int> rems;
        int val = sum;
        while(val%9!=0){
            val++;
        }
        rems.push_back(val-sum);
        for(int i = 0; i<10; i++){
            val+=9;
            rems.push_back(val-sum);
        }
        // for(auto it: rems){
        //     cout << it << " ";
        // }
        // cout << "\n";

        bool found = 0;
        for(int i = 0; i<rems.size(); i++){
            int zero = rems[i];
            int tmp1 = two, tmp2 = three;
            while(zero!=0){
                if(zero>=6 and tmp2){
                    zero-=6;
                    tmp2--;
                }
                else if(zero>=2 and tmp1){
                    zero-=2;
                    tmp1--;
                }
                else{
                    break;
                }
            }
            if(zero==0){
                found = 1;
                break;
            }
        }
        if(found){
            cout << "YES\n";
        }
        else{
            cout << "NO\n";
        }
    }
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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

#define int long long
#define vi vector<int>
#define f(i, a, n) for (int i = a; i < n; i++)
#define pb push_back


int32_t main() {
    int t;
    cin >> t;
    while (t--) {
      int n;
      cin>>n;
      vi v(n);
      f(i,0,n)cin>>v[i];
      if(v[0]>v[1]){
        cout<<"NO\n";
        continue;
      }
      int flg=0;
      f(i,1,n){
        if(i==n-1 ){
            if(v[i]<v[i-1]){
                cout<<"NO\n";
                flg++;
                break;
            }
            
        }
        else if(v[i]-v[i-1]>v[i+1]){
            cout<<"NO\n";
            flg++;
            break;
        }
        v[i]=v[i]-v[i-1];
      }
      if(flg==0)cout<<"YES\n";
    }
    return 0;
}


Solution 2 (runtime: 328 ms):
#define  ashfn

#include <iostream>

#include <cmath>

#include <vector>

#include <utility>

#include <map>

#include <set>

#include <algorithm>

#include <iomanip>

#include <bitset>

#include <unordered_set>

#include <queue>

#include <unordered_map>



#define el "\n"

#define vecdebug(list) for(auto vecdebugitem : list){ cout << vecdebugitem <<","; }cout << el

#define tcl int tci=0; tci<tc; tci++

#define iint(name) int name; cin >> name



using namespace std;

typedef long long ll;

typedef long double ld;



void solve() {

iint(n);



int nums[n];



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

cin >> nums[i];

}



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

int mn = min(nums[i], nums[i+1]);

nums[i]-=mn;

nums[i+1]-=mn;

}



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

if(nums[i]!=0){

cout << "NO" << el;

return;

}

}



cout << "YES" << el;



}



int main() {

iint(tc);

for(tcl){

solve();

}

return 0;

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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main() {
    int t=1;
    cin>>t;
    while(t--){
    //    int n;
    //    cin>>n;
        string s;
        cin>>s;
        int n=s.size();
        // map<int,int>mpp;
        // priority_queue<char>pq;
        r(i,n){
            int maxi=0,ind=i;
            // if(!mpp[i])
            maxi=s[i]-'0';
            for(int j=i;j<min(n,i+10);j++){
                if((s[j]-'0')-(j-i)>maxi){
                    maxi=(s[j]-'0')-(j-i);
                    ind=j;
                }
            }
        while(ind>i){
            swap(s[ind],s[ind-1]);
            ind--;
        }
         s[i]=(maxi+'0');
        }
    cout<<s<<endl;

    }
}

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

using namespace std;



int main() {

ios_base::sync_with_stdio(false);

cin.tie(nullptr);

int t;

cin >> t;

while(t--)

{

string u;

cin >> u;

vector<int> e;

for(char it : u)

{

e.push_back(it - '0');

}

for(int i = 0;i<e.size();i++)

{

int expected = e[i]+2;

int swapee = 0;

for(int j = i+1;j<=i+8-e[i] && j < e.size();j++) // check what happens if you loosen the constraints (ex : j<=i+8-e[i]+10)

{

if(expected <= e[j])

{

swapee = j;

expected = e[j]+1;



}

expected++;

}

if(swapee)

{

int h = e[swapee];

for(int f = swapee;f>i;f--)

{

e[f] = e[f-1];

}

e[i] = h+i-swapee;

}

}

for(auto it : e)

{

cout << it;

}

cout << '\n';

}

}