ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;
void solve()
{
    long n;
    cin >> n;
    long check = 0;
    long twos = 0;
    long threes = 0;
    for (long i = 10; n != 0;)
    {
        if (n % i == 2)
        {
            twos++;
        }
        if (n % i == 3)
        {
            threes++;
        }
        check += n % i;
        n /= 10;
    }
    for (int i = 0; i <= twos; i++)
    {
        for (int j = 0; j <= threes; j++)
        {
            int tsum = check;
            tsum += j * 6 + i * 2;
            if (tsum % 9 == 0)
            {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}
int main()
{
    long t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;
void solve()
{
    long n;
    cin >> n;
    long check = 0;
    long twos = 0;
    long threes = 0;
    for (long i = 10; n != 0;)
    {
        if (n % i == 2)
        {
            twos++;
        }
        if (n % i == 3)
        {
            threes++;
        }
        check += n % i;
        n /= 10;
        check %= 9;
    }
    for (int i = 0; i <= twos; i++)
    {
        for (int j = 0; j <= threes; j++)
        {
            int tsum = check;
            tsum += j * 6 + i * 2;
            if (tsum % 9 == 0)
            {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}
int main()
{
    long t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

using namespace std;
void solve()
{
    string s;
    cin >> s;
    int sum = 0, twos = 0, threes = 0;
    for (auto i : s)
    {
        if (i == '2')
        {
            twos++;
        }
        else if (i == '3')
        {
            threes++;
        }
        sum += (i - '0');
        sum %= 9;
    }

    for (int i = 0; i <= threes; i++)
    {
        for (int j = 0; j < twos; j++)
        {
            long tsum = sum;
            tsum += j * 2 + i * 6;
            if (tsum % 9 == 0)
            {
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
}
int main()
{
    long t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

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

using namespace std;
void solve()
{
    string s;
    cin >> s;
    int sum = 0, twos = 0, threes = 0;
    for (auto i : s)
    {
        if (i == '2')
        {
            twos++;
        }
        else if (i == '3')
        {
            threes++;
        }
        sum += (i - '0');
        sum %= 9;
    }

    for (int i = 0; i <= threes; i++)
    {
        for (int j = 0; j <= twos; j++)
        {
            long tsum = sum;
            tsum += j * 2 + i * 6;
            if (tsum % 9 == 0)
            {
                cout << "YES" << endl;
                return;
            }
        }
    }
    cout << "NO" << endl;
}
int main()
{
    long t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


Submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long 
#define ld long long
void solve(){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i!=0) a[i]=min(a[i],a[i-1]);
    }
    cout<<(is_sorted(a,a+n) ? "Yes" : "No")<<endl;
}
signed main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long 
#define ld long long
void solve(){
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i!=0) a[i]=min(a[i],a[i-1]);
    }
    cout<<(is_sorted(a,a+n) ? "Yes" : "No")<<endl;
}
signed main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
}



Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long long
void solve(){
    int n;cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i!=0) a[i]=min(a[i],a[i-1]);
    }
    cout<<(is_sorted(a.begin(),a.end()) ? "Yes" : "No")<<endl;
}
signed main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long long
void solve(){
    int n;cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i!=0) a[i]=min(a[i],a[i-1]);
    }
    cout<<(is_sorted(a.begin(),a.end()) ? "Yes" : "No")<<endl;
}
signed main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long long
void solve(){
    int n;cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i!=0){
            int x=min(a[i],a[i-1]);
            a[i]-=x;
            a[i-1]-=x;
        }

    }
    cout<<(is_sorted(a.begin(),a.end()) ? "YES" : "NO")<<endl;
}
signed main(){
    int t;cin>>t;
    while(t--){
        solve();
    }
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 16):
#include<bits/stdc++.h>
#define int long long
#define fastio() ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int dp[1001][1001];
int solve(int indexa,int indexb,int indexc,string a,string b,string c){
    int mine=INT_MAX;
     if(indexa<(int)a.size() && indexb>=(int)b.size()){
           if(c[indexc]!=a[indexa]){
                if(dp[indexa+1][indexb]==-1){
                    dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                }
                mine=min(mine,1+dp[indexa+1][indexb]);
           }
           else{
                if(dp[indexa+1][indexb]==-1){
                    dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                }
                mine=min(mine,dp[indexa+1][indexb]);
           }
     }
     else if(indexa>=(int)a.size() && indexb<(int)b.size()){
            if(c[indexc]!=b[indexb]){
                if(dp[indexa][indexb+1]==-1){
                    dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                }
                mine=min(mine,1+dp[indexa][indexb+1]);
           }
           else{
                if(dp[indexa][indexb+1]==-1){
                    dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                }
                mine=min(mine,dp[indexa][indexb+1]);
           }
     }
     else if(indexa<(int)a.size() && indexb<(int)b.size()){
                 if(c[indexc]!=a[indexa]){
                    if(dp[indexa+1][indexb]==-1){
                        dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                    }
                    mine=min(mine,1+dp[indexa+1][indexb]);
                 }
                 else{
                    if(dp[indexa+1][indexb]==-1){
                        dp[indexa+1][indexb]=solve(indexa+1,indexb,indexc+1,a,b,c);
                    }
                    mine=min(mine,dp[indexa+1][indexb]);
                 }
                 if(c[indexc]!=b[indexb]){
                     if(dp[indexa][indexb+1]==-1){
                        dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                    }
                    mine=min(mine,1+dp[indexa][indexb+1]);
                 }
                 else{
                      if(dp[indexa][indexb+1]==-1){
                        dp[indexa][indexb+1]=solve(indexa,indexb+1,indexc+1,a,b,c);
                    }
                    mine=min(mine,dp[indexa][indexb+1]);
                 }
     }
     else{
        mine=min(mine,(int)0);
     }
     return mine;
}
int32_t main(){
    fastio();
    int t;
    cin>>t;
    while(t--){
        string a,b,c;
        cin>>a>>b>>c;
        int indexa=0,indexb=0,indexc=0;;
        memset(dp,-1,sizeof(dp));
        dp[indexa][indexb]=solve(indexa,indexb,indexc,a,b,c);
        cout<<dp[indexa][indexb]<<"\n";
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=1005;
int n,c[N];
vector<pii> ans;

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(0,n,i) cin>>c[i];

    for_n(0,n,i)
    for_n(i+1,n,j)
    {
        ans.push_back({c[i],c[j]});
        if(c[j]>c[i])
        {
            ans.push_back({c[j],c[i]});
        }
    }
    cout<<ans.size()<<'\n';
    for_e(a,ans)
    cout<<a.first<<' '<<a.second<<'\n';

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>
#include <stack>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=1005;
int n,c[N];
stack<pii> ans;

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(0,n,i) cin>>c[i];

    for_n(0,n,i)
    for_n(i+1,n,j)
    {
        ans.push({c[i],c[j]});
        if(c[j]>c[i])
        {
            ans.push({c[j],c[i]});
        }
    }
    cout<<ans.size()<<'\n';
    
    while(!ans.empty())
    {
        auto a = ans.top();
        cout<<a.first<<' '<<a.second<<'\n';
        ans.pop();
    }

    return 0;
}


Submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=1005;
int n,c[N];
vector<pii> ans;

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(0,n,i) cin>>c[i];

    for_n(0,n,i)
    for_n(i+1,n,j)
    {
        if(c[j]>c[i])
        {
            ans.push_back({c[i],c[j]});
        }
        ans.push_back({c[j],c[i]});
    }

    sort(all(ans));
    cout<<ans.size()<<'\n';
    for_e(a,ans)
    cout<<a.second<<' '<<a.first<<'\n';

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=1005;
int n,c[N];
vector<pii> ans;

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(0,n,i) cin>>c[i];

    for_n(0,n,i)
    for_n(i+1,n,j)
    {
        ans.push_back({c[i],c[j]});
        if(c[j]>c[i])
        {
            ans.push_back({c[j],c[i]});
        }
    }
    cout<<ans.size()<<'\n';
    for_e(a,ans)
    cout<<a.first<<' '<<a.second<<'\n';

    return 0;
}


Submission (verdict: Wrong answer on test 1):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>
#include <stack>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=1005;
int n,c[N];
stack<pii> ans;

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(0,n,i) cin>>c[i];

    for_n(0,n,i)
    for_n(i+1,n,j)
    {
        ans.push({c[i],c[j]});
        if(c[j]>c[i])
        {
            ans.push({c[j],c[i]});
        }
    }
    cout<<ans.size()<<'\n';
    
    while(!ans.empty())
    {
        auto a = ans.top();
        cout<<a.first<<' '<<a.second<<'\n';
        ans.pop();
    }

    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=1005;
int n,c[N];
vector<pii> ans;

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(0,n,i) cin>>c[i];

    for_n(0,n,i)
    for_n(i+1,n,j)
    {
        if(c[j]>c[i])
        {
            ans.push_back({c[i],c[j]});
        }
        ans.push_back({c[j],c[i]});
    }

    sort(all(ans));
    cout<<ans.size()<<'\n';
    for_e(a,ans)
    cout<<a.second<<' '<<a.first<<'\n';

    return 0;
}


Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>
 
using namespace std;
 
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;
 
#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define pb push_back
 
const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }
 
const int directions[4][2]={-1,0,0,-1,0,1,1,0};
 
const int N=1005;
int n,c[N],f[N];
vector<pii> ans;
set<int> nums;
 
signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n;
    for_n(1,n+1,i)
    {
        int v; cin>>v;
        c[v]=i;
        f[i]=v;
        nums.insert(i);
    }

    for(int i=1;i<=n;i++)
    {
        auto it=nums.upper_bound(f[i]);
        while(it!=nums.end())
        {
            // if(c[f[i]]>c[*it]) break;
            ans.pb({*it,f[i]});
            it++;
        }
        nums.erase(f[i]);
        auto rit=nums.rbegin();
        while(rit!=nums.rend())
        {
            ans.pb({f[i],*rit});
            rit++;
        }
    }

    cout<<ans.size()<<'\n';
    for_e(a,ans) cout<<a.first<<' '<<a.second<<'\n';
 
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define clr(arr) memset(arr,0,sizeof(arr))
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=2e5+5;
int n,t,a[N];

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>t;
    while(t--)
    {
        bool valid=true;
        multiset<pii> s;
        cin>>n;
        
        for_n(0,n,i)
        {
            cin>>a[i];
            s.insert({a[i],i});
        }
        vi pre(n,1e10);
        pre[n-1]=a[n-1];
        for(int i=n-2;i>=0;i--) pre[i]=min(pre[i],pre[i+1]);

        for_n(0,n,i)
        {
            if(a[i]>pre[i])
            {
                if(a[i]<a[i+1])
                {
                    a[i+1]-=a[i];
                    a[i]=0;
                }
                else
                {
                    valid=false;
                    break;
                }
            }
        }
        // for_n(0,n,i)
        //     cout<<a[i]<<' ';
        cout<<(valid?"YES":"NO")<<'\n';
    }
    return 0;
}


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define clr(arr) memset(arr,0,sizeof(arr))
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=2e5+5;
int n,t,a[N];

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>t;
    while(t--)
    {
        cin>>n;
        
        for_n(0,n,i)
        {
            cin>>a[i];
        }

        for_n(0,n,i)
        {
            if(a[i]<a[i+1])
            {
                a[i+1]-=a[i];
                a[i]=0;
            }
        }
        cout<<(is_sorted(a,a+n)?"YES":"NO")<<'\n';
    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <cstring>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <map>

using namespace std;

typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long> vl;
typedef string str;
typedef pair<int, int> pii;
typedef pair<long, long> pllll;

#define all(a) a.begin(), a.end()
#define Debug(x) cout << #x " = " << (x) << '\n'
#define for_n(s, e, i) for (ll i = s; i < e; i++)
#define for_e(e,of) for (auto& e : of)
#define clr(arr) memset(arr,0,sizeof(arr))
#define pb push_back

const ll MOD=1e9+7;
ll madd(ll a, ll b) { return (a + b) % MOD; }

const int directions[4][2]={-1,0,0,-1,0,1,1,0};

const int N=2e5+5;
int n,t,a[N];

signed main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>t;
    while(t--)
    {
        bool valid=true;
        multiset<pii> s;
        cin>>n;
        
        for_n(0,n,i)
        {
            cin>>a[i];
            s.insert({a[i],i});
        }
        vi pre(n);
        pre[n-1]=a[n-1];
        for(int i=n-2;i>=0;i--) pre[i]=min(pre[i],pre[i-1]);
        
        for_n(0,n,i)
        {
            s.extract({a[i],i});
            if(a[i]>pre[i])
            {
                auto it=s.upper_bound({a[i]-pre[i],1e10});
    
                if(it==s.end())
                {
                    valid=false;
                    break;
                }
    
                a[i]-=it->first;
                a[it->second]=0;
                s.extract(it);
            }
        }
        cout<<(valid?"YES":"NO")<<'\n';
    }
    return 0;
}