ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using ll= long long int;
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    int n,l,r;
    cin>>n>>l>>r;
    vector<ll>a(n);
    vector<ll>b,c;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i<r)
        {
            b.push_back(a[i]);
        }
        if(i>=l-1)
        {
            c.push_back(a[i]); 
        }
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());    
    
    int ans1=0,ans2=0;
    for(int i=0;i<r-l+1;i++)
    {
        ans1=ans1+b[i];
        ans2=ans2+c[i];
    }
    cout<<"ans"<<(ans1<ans2?ans1:ans2)<<endl;
   }
    return 0;
}

Submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using ll= long long int;
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    int n,l,r;
    cin>>n>>l>>r;
    vector<ll>a(n);
    vector<ll>b,c;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i<r)
        {
            b.push_back(a[i]);
        }
        if(i>=l-1)
        {
            c.push_back(a[i]); 
        }
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());    
    
    int ans1=0,ans2=0;
    for(int i=0;i<r-l+1;i++)
    {
        ans1=ans1+b[i];
        ans2=ans2+c[i];
    }
    cout<<(ans1<ans2?ans1:ans2)<<endl;
   }
    return 0;
}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 8):
#include <bits/stdc++.h>
using ll= long long int;
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    int n,l,r;
    cin>>n>>l>>r;
    vector<ll>a(n);
    vector<ll>b,c;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i<r)
        {
            b.push_back(a[i]);
        }
        if(i>=l-1)
        {
            c.push_back(a[i]); 
        }
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());    
    
    int ans1=0,ans2=0;
    for(int i=0;i<r-l+1;i++)
    {
        ans1=ans1+b[i];
        ans2=ans2+c[i];
    }
    cout<<(ans1<ans2?ans1:ans2)<<endl;
   }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using ll= long long int;

using namespace std;

int main()

{

    int t;

    cin>>t;

    while(t--)

    {

    int n,l,r;

    cin>>n>>l>>r;

    vector<ll>a(n);

    vector<ll>b,c;

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

    {

        cin>>a[i];

        if(i<r)

        {

            b.push_back(a[i]);

        }

        if(i>=l-1)

        {

            c.push_back(a[i]); 

        }

    }

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

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

    

    ll ans1=0,ans2=0;

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

    {

        ans1=ans1+b[i];

        ans2=ans2+c[i];

    }

    cout<<(ans1<ans2?ans1:ans2)<<endl;

   }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using ll= long long int;
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
    int n,l,r;
    cin>>n>>l>>r;
    vector<ll>a(n);
    vector<ll>b,c;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i<r)
        {
            b.push_back(a[i]);
        }
        if(i>=l-1)
        {
            c.push_back(a[i]); 
        }
    }
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());    
    
    int ans1=0,ans2=0;
    for(int i=0;i<r-l+1;i++)
    {
        ans1=ans1+b[i];
        ans2=ans2+c[i];
    }
    cout<<"ans"<<(ans1<ans2?ans1:ans2)<<endl;
   }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fori(i, a, b) for(int i = a; i < b; ++i)
#define rfori(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define clr(a) memset(a, 0, sizeof(a))
#define set_mem(a, b) memset(a, b, sizeof(a))
#define sz(v) (int)v.size()
#define umap unordered_map
#define uset unordered_set
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pq priority_queue
#define minpq(x) priority_queue<x, vector<x>, greater<x>>

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

void solve() {
    ll n; 
    cin >> n;
    ll cntT = 0, cntTh = 0, sum = 0;
    string num = to_string(n);

    for (auto it : num) {
        if (it == '2') cntT++;
        if (it == '3') cntTh++;
        sum += (it - '0');
    }

    int need = (9 - (sum % 9)) % 9;

    while(need%2!=0 && need<(cntT*2+cntTh*6)) need+=9;
    while (need % 9 != 0) {
        if (need % 2 == 0 && cntT > 0) {
            need -= 2;
            cntT--;
        } else if (need % 6 == 0 && cntTh > 0) {
            need -= 6;
            cntTh--;
        } else {
            break; 
        }
    }

    if (need % 9 == 0) 
        cout << "YES\n";
        
    else 
        cout <<"NO\n";
}


int main() {
    fast_io;

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

    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fori(i, a, b) for(int i = a; i < b; ++i)
#define rfori(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define clr(a) memset(a, 0, sizeof(a))
#define set_mem(a, b) memset(a, b, sizeof(a))
#define sz(v) (int)v.size()
#define umap unordered_map
#define uset unordered_set
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pq priority_queue
#define minpq(x) priority_queue<x, vector<x>, greater<x>>

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

void solve()
{
    string s;
    cin >> s;
    int n = s.length();

    for (int i = 0; i < n; i++) {
        string temp = s;
        int maxi = INT_MIN;
        int idx = i;
        
     
        for (int j = i + 1; j < n; j++) {
            if ((s[j] - '0'-(j-i)) > maxi-(idx-i) && idx>=0) {
                maxi = s[j] - '0'; 
                idx = j;   
            }
        }

   
        if (maxi - (idx-i)> (s[i] - '0')) {
            
            char maxChar = s[idx]-(idx-i);
            for (int j = idx; j > i; j--) {
                s[j] = s[j - 1];
            }
            s[i] = maxChar;
        }
    }

    cout << s << endl;
    



























    // int maxi = INT_MIN;
    // int cnt = 1;
    // vector<pair<int,int>> maxArr(n,{-1,cnt});

    // for(int i=n-1;i>=0;i--){
    //     if(maxi == s[i]-'0') cnt++;
    //     if(s[i]-'0'>maxi) maxi = s[i]-'0';
        
    //     maxArr[i].f = max(s[i]-'0',maxi);
    //     maxArr[i].s = cnt;
    // }
    // for(auto it:maxArr){
    //     cout<<it.f<<","<<it.s<<" ";

    // }
    // cout<<endl;
}

int main() {
    fast_io;

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

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
///sadekalprince31
#include<bits/stdc++.h>
#define ll long long
#define en endl
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define yes cout << "YES\n";
#define no cout << "NO\n";
const ll MOD = 1e9 + 7;
const ll N = 1e10;
using namespace std;

signed main()
{
    op();
    tc
    {
    ll n, i, ans;
    cin >> n;
    vl v1(n);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
        ans += v1[i];
    }
    while (n > 1)
    {
 
        ll res = 0;
        for (i = 0; i < (n - 1); i++)
        {
            v1[i] = v1[i + 1] - v1[i];
            res += v1[i];
        }
        v1.pop_back();
        ans = max(ans, abs(res));
        n--;
    }
    cout << ans << en;
    }

}

///THE__END///


Submission (verdict: Wrong answer on test 1):
///sadekalprince31
#include<bits/stdc++.h>
#define ll long long
#define en endl
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define yes cout << "YES\n";
#define no cout << "NO\n";
const ll MOD = 1e9 + 7;
const ll N = 1e10;
using namespace std;

signed main()
{
    op();
    tc
    {
    ll n, i, ans=1;
    cin >> n;
    vl v1(n);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
        ans += v1[i];
    }
    while (n > 1)
    {
 
        ll res = 0;
        for (i = 0; i < (n - 1); i++)
        {
            v1[i] = v1[i + 1] - v1[i];
            res += v1[i];
        }
        v1.pop_back();
        ans = max(ans, abs(res));
        n--;
    }
    cout << ans << en;
    }

}

///THE__END///
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
///sadekalprince31
#include<bits/stdc++.h>
#define ll long long
#define en endl
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define yes cout << "YES\n";
#define no cout << "NO\n";
const ll MOD = 1e9 + 7;
const ll N = 1e10;
using namespace std;

signed main()
{
    op();
    tc
    {
    ll n, i, ans;
    cin >> n;
    vl v1(n);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
        ans += v1[i];
    }
    while (n > 1)
    {
 
        ll res = 0;
        for (i = 0; i < (n - 1); i++)
        {
            v1[i] = v1[i + 1] - v1[i];
            res += v1[i];
        }
        v1.pop_back();
        ans = max(ans, abs(res));
        n--;
    }
    cout << ans << en;
    }

}

///THE__END///
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
///sadekalprince31
#include<bits/stdc++.h>
#define ll long long
#define en endl
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define yes cout << "YES\n";
#define no cout << "NO\n";
const ll MOD = 1e9 + 7;
const ll N = 1e10;
using namespace std;

signed main()
{
    op();
    tc
    {
    ll n, i, ans=1;
    cin >> n;
    vl v1(n);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
        ans += v1[i];
    }
    while (n > 1)
    {
 
        ll res = 0;
        for (i = 0; i < (n - 1); i++)
        {
            v1[i] = v1[i + 1] - v1[i];
            res += v1[i];
        }
        v1.pop_back();
        ans = max(ans, abs(res));
        n--;
    }
    cout << ans << en;
    }

}

///THE__END///


Submission (verdict: Accepted):
///sadekalprince31
#include<bits/stdc++.h>
#define ll long long
#define en endl
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define yes cout << "YES\n";
#define no cout << "NO\n";
const ll MOD = 1e9 + 7;
const ll N = 1e10;
using namespace std;

signed main()
{
    op();
    tc
    {
    ll n, i, ans=0;
    cin >> n;
    vl v1(n);
    for (i = 0; i < n; i++)
    {
        cin >> v1[i];
        ans += v1[i];
    }
    while (n > 1)
    {
 
        ll res = 0;
        for (i = 0; i < (n - 1); i++)
        {
            v1[i] = v1[i + 1] - v1[i];
            res += v1[i];
        }
        v1.pop_back();
        ans = max(ans, abs(res));
        n--;
    }
    cout << ans << en;
    }

}

///THE__END///
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=true;
		for(int i=0;i<n-1;i+=2)
		{
			if(arr[i]>arr[i+1])
            {
                flag=false;
                break;
            }
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	ll n;
	cin>>n;
	vector<ll> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=true;
		for(int i=0;i<n-1;i++)
		{
			if(arr[i]>arr[i+1])
            {
                flag=false; 
                break;
            }
            else if(arr[i]<arr[i+1])
            {
                arr[i+1]-=arr[i];
                arr[i]=0;
            }
            else
            {
                arr[i]=0;
                arr[i+1]=0;
            }
		}
        // for(int i=0;i<n;i++) cout<<arr[i]<<" ";
        // cout<<"\n";
		if(flag)
        {
            if(is_sorted(arr.begin(),arr.end()))
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
        }
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=true;
		for(int i=1;i<n;i+=2)
		{
			if(arr[i-1]>arr[i])
            {
                flag=false;
                break;
            }
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=true;
		for(int i=0;i<n-1;i+=2)
		{
			if(arr[i]>arr[i+1])
            {
                flag=false;
                break;
            }
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=false;
		for(int i=1;i<n;i++)
		{
			int mi=min(arr[i],arr[i-1]);
			arr[i]-=mi;
			arr[i-1]-=mi;
			if(is_sorted(arr.begin(),arr.end()))
			{
				flag=true;
				break;
			}
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=true;
		for(int i=1;i<n;i+=2)
		{
			if(arr[i-1]>arr[i])
            {
                flag=false;
                break;
            }
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 8):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed solve()
{
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i=0;i<n;i++) cin>>arr[i];
	if(is_sorted(arr.begin(),arr.end()))
	{
		cout<<"YES"<<endl;
		return 0;
	}
	else
	{
		bool flag=false;
		for(int i=1;i<n;i++)
		{
			int mi=min(arr[i],arr[i-1]);
			arr[i]-=mi;
			arr[i-1]-=mi;
			if(is_sorted(arr.begin(),arr.end()))
			{
				flag=true;
				break;
			}
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
    return 0;
}
signed main()
{
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    //t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

bool is_non_decreasing(const vector<int>& a) {
    for (size_t i = 0; i + 1 < a.size(); ++i) {
        if (a[i] > a[i + 1]) {
            return false;
        }
    }
    return true;
}

string solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (int pass = 0; pass < n; ++pass) {
        bool changed_in_pass = false;
        for (int i = 0; i < n - 1; ++i) {
            if (a[i] > a[i + 1]) {
                int min_val = min(a[i], a[i + 1]);
                a[i] -= min_val;
                a[i + 1] -= min_val;
                changed_in_pass = true;
            }
        }
        if (!changed_in_pass) {
            break;
        }
    }

    if (is_non_decreasing(a)) {
        return "YES";
    } else {
        return "NO";
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 1):
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

bool is_non_decreasing(const vector<int>& a) {
    for (size_t i = 0; i + 1 < a.size(); ++i) {
        if (a[i] > a[i + 1]) {
            return false;
        }
    }
    return true;
}

string solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    bool changed = true;
    while (changed) {
        changed = false;
        for (int i = 0; i < n - 1; ++i) {
            if (a[i] > a[i + 1]) {
                int m = min(a[i], a[i + 1]);
                a[i] -= m;
                a[i + 1] -= m;
                changed = true;
            }
        }
    }

    if (is_non_decreasing(a)) {
        return "YES";
    } else {
        return "NO";
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << endl;
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

bool is_non_decreasing(const vector<int>& a) {
    for (size_t i = 0; i + 1 < a.size(); ++i) {
        if (a[i] > a[i + 1]) {
            return false;
        }
    }
    return true;
}

string solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    bool changed = true;
    while (changed) {
        changed = false;
        for (int i = 0; i < n - 1; ++i) {
            if (a[i] > a[i + 1]) {
                int m = min(a[i], a[i + 1]);
                a[i] -= m;
                a[i + 1] -= m;
                changed = true;
            }
        }
    }

    if (is_non_decreasing(a)) {
        return "YES";
    } else {
        return "NO";
    }
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        cout << solve() << endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
 
        bool possible = true;
        long long carry = a[0]; // c_1 = a_1
        for (int i = 1; i < n; i++){
            if(carry > a[i]){
                possible = false;
                break;
            }
            // Set c_i = a[i] - c_{i-1}
            carry = a[i] - carry;
        }
        cout << (possible ? "YES" : "NO") << "\n";
    }
    return 0;
}