ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050D - Digital string maximization
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <iostream>
#include <vector>
#define int int64_t


using namespace std;

void update (int pos, std::string& input_d) {
    int max_ = input_d[pos];
    int max_idx_ = pos;
    for (int i = 1; (i < 8) && (pos + i < input_d.size()); ++i) {
        if (input_d[pos + i] - i > max_) {
            max_ = input_d[pos + i] - i;
            max_idx_ = pos + i;
        }
    }
    for (int i = max_idx_; i > pos; --i) {
        input_d[i] = input_d[i - 1];
    }
    input_d[pos] = max_;
}

signed main() {
    int t;
    cin >> t;
    while (t--) {
        string input_d;
        cin >> input_d;
        for (int i = 0; i + 1 < input_d.size(); ++i){
            update(i, input_d);
        }
        cout << input_d << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::map<int, int> cnt{};
        for (int num : v)
           cnt[num]++;

        int ans = std::set(all(cnt)).size();
        std::vector<std::pair<int, int>> pairs(cnt.begin(), cnt.end());
        std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b)
        {
            return a.second < b.second;
        });

        for(int i = 0; i < pairs.size(); i++)
        {
            if(k <= 0 || ans == 1)
                break;
            else
            {
                ans--;
                k -= pairs[i].second;
            }
        }

        std::cout << ans << '\n';
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::map<int, int> cnt{};
        for (int num : v)
           cnt[num]++;

        int ans = std::set(all(v)).size();
        std::vector<std::pair<int, int>> pairs(cnt.begin(), cnt.end());
        std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b)
        {
            return a.second < b.second;
        });

        for(int i = 0; i < pairs.size(); i++)
        {
            if(k <= 0)
                break;
            else
            {
                ans--;
                k -= pairs[i].second;
            }
        }

        if(ans == 0)
            std::cout << 1 << '\n';
        else
            std::cout << ans << '\n';
    }
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

/*
stole from editorial, my intuition was correct about it being
"base state of ans is the num of unique elements, to get minimum value of f(a) we reduce
the number of unique elements", just that my implementation was incorrect.
*/

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::sort(all(v));
        std::vector<int> cnt = {1};
        for (int i = 1; i < n; i++)
        {
            if (v[i] == v[i - 1])
                cnt.back()++;
            else
                cnt.emplace_back(1);
        }
        std::sort(all(cnt));
        int m = cnt.size(); bool chk{false};
        for (int i = 0; i < m - 1; i++)
        {
            if (cnt[i] > k)
            {
                std::cout << m - i << "\n";
                chk = true;
                break;
            }
            k -= cnt[i];
        }
        if(!chk)
           std::cout << 1 << "\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::map<int, int> cnt{};
        for (int num : v)
           cnt[num]++;

        int ans = std::set(all(cnt)).size();
        std::vector<std::pair<int, int>> pairs(cnt.begin(), cnt.end());
        std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b)
        {
            return a.second < b.second;
        });

        for(int i = 0; i < pairs.size(); i++)
        {
            if(k <= 0 || ans == 1)
                break;
            else
            {
                ans--;
                k -= pairs[i].second;
            }
        }

        std::cout << ans << '\n';
    }
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
typedef unsigned long long ull;

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

    int t{};
    std::cin >> t;
    while (t--)
    {
        int n{}, k{};
        std::cin >> n >> k;

        std::vector<int> v(n);
        for(auto& x : v) std::cin >> x;

        std::map<int, int> cnt{};
        for (int num : v)
           cnt[num]++;

        int ans = std::set(all(v)).size();
        std::vector<std::pair<int, int>> pairs(cnt.begin(), cnt.end());
        std::sort(pairs.begin(), pairs.end(), [](const auto& a, const auto& b)
        {
            return a.second < b.second;
        });

        for(int i = 0; i < pairs.size(); i++)
        {
            if(k <= 0)
                break;
            else
            {
                ans--;
                k -= pairs[i].second;
            }
        }

        if(ans == 0)
            std::cout << 1 << '\n';
        else
            std::cout << ans << '\n';
    }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int min(int x,int y){
    if(x<=y)return x;
    return y;
}

bool fn(int count2,int count3,int sum){
    // cout<<"ggg"<<count2<<count3<<sum<<endl;
    for(int i=0;i<=min(100,count2);i++){
           for(int j=0;j<=min(100,count3);j++){
               int sum1=sum+i*2+j*6;
            //   if(i==0&&j==2)cout<<sum1<<"ggdd"<<endl;
               if(sum1%9==0){
                   return true;
               }
           }
       }
       return false;
}
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       int n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
       while(n!=0){
           if(n%10==2)count2++;
           if(n%10==3)count3++;
           sum+=n%10;
           n=n/10;
       }
       int req=9-(sum%9);
      if(fn(count2,count3,sum))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
       
       
        
    }

    return 0;
}

Submission (verdict: Accepted):

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int min(int x,int y){
    if(x<=y)return x;
    return y;
}

bool fn(int count2,int count3,int sum){
    // cout<<"ggg"<<count2<<count3<<sum<<endl;
    for(int i=0;i<=min(100,count2);i++){
           for(int j=0;j<=min(100,count3);j++){
               int sum1=sum+i*2+j*6;
            //   if(i==0&&j==2)cout<<sum1<<"ggdd"<<endl;
               if(sum1%9==0){
                   return true;
               }
           }
       }
       return false;
}
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       string n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
    //   while(n!=0){
    //       if(n%10==2)count2++;
    //       if(n%10==3)count3++;
    //       sum+=n%10;
    //       n=n/10;
    //   
        
    for(int i=0;i<n.size();i++){
        if(n[i]=='2')count2++;
        if(n[i]=='3')count3++;
        sum+=(n[i]-'0');
    }
       
      if(fn(count2,count3,sum))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
       
       
        
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       int n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
       while(n!=0){
           if(n%10==2)count2++;
           if(n%10==3)count3++;
           sum+=n%10;
           n=n/10;
       }
       int req=9-(sum%9);
       
       if(req==3||req==6){
           if(req==3){
               if(count2>=6||count3>=2)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }else{
               if(count2>=3||count3>=1)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           
       }else{
           if(req==9){
               cout<<"yes"<<endl;
           }
           else if(req==1){
               if(count2>=5)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==2){
               if(count2>=1)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==4){
               if(count2>=2)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==5){
               if(count2>=7)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==7){
               if(count2>=5)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==8){
               if(count2>=7)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           
       }
       
        
    }

    return 0;
}

Submission (verdict: Wrong answer on test 3):

#include <bits/stdc++.h>
using namespace std;
int min(int x,int y){
    if(x<=y)return x;
    return y;
}
#define int long long 
bool fn(int count2,int count3,int sum){
    // cout<<"ggg"<<count2<<count3<<sum<<endl;
    for(int i=0;i<=min(100,count2);i++){
           for(int j=0;j<=min(100,count3);j++){
               int sum1=sum+i*2+j*6;
            //   if(i==0&&j==2)cout<<sum1<<"ggdd"<<endl;
               if(sum1%9==0){
                   return true;
               }
           }
       }
       return false;
}
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       int n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
       while(n!=0){
           if(n%10==2)count2++;
           if(n%10==3)count3++;
           sum+=n%10;
           n=n/10;
       }
       int req=9-(sum%9);
      if(fn(count2,count3,sum))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
       
       
        
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       int n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
       while(n!=0){
           if(n%10==2)count2++;
           if(n%10==3)count3++;
           sum+=n%10;
           n=n/10;
       }
       int req=9-(sum%9);
       
       if(req==3||req==6){
           if(req==3){
               if(count2>=6||count3>=2)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }else{
               if(count2>=3||count3>=6)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           
       }else{
           if(req==9){
               cout<<"yes"<<endl;
           }
           else if(req==1){
               if(count2>=5)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==2){
               if(count2>=1)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==4){
               if(count2>=2)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==5){
               if(count2>=7)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==7){
               if(count2>=5)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           else if(req==8){
               if(count2>=7)cout<<"yes"<<endl;
               else cout<<"no"<<endl;
           }
           
       }
       
        
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):

#include <bits/stdc++.h>
using namespace std;
int min(int x,int y){
    if(x<=y)return x;
    return y;
}
#define int long long 
bool fn(int count2,int count3,int sum){
    // cout<<"ggg"<<count2<<count3<<sum<<endl;
    for(int i=0;i<=min(100,count2);i++){
           for(int j=0;j<=min(100,count3);j++){
               int sum1=sum+i*2+j*6;
            //   if(i==0&&j==2)cout<<sum1<<"ggdd"<<endl;
               if(sum1%9==0){
                   return true;
               }
           }
       }
       return false;
}
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       int n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
       while(n!=0){
           if(n%10==2)count2++;
           if(n%10==3)count3++;
           sum+=n%10;
           n=n/10;
       }
       int req=9-(sum%9);
      if(fn(count2,count3,sum))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
       
       
        
    }

    return 0;
}

Submission (verdict: Wrong answer on test 3):

#include <bits/stdc++.h>
using namespace std;
#define int long long 
int min(int x,int y){
    if(x<=y)return x;
    return y;
}

bool fn(int count2,int count3,int sum){
    // cout<<"ggg"<<count2<<count3<<sum<<endl;
    for(int i=0;i<=min(100,count2);i++){
           for(int j=0;j<=min(100,count3);j++){
               int sum1=sum+i*2+j*6;
            //   if(i==0&&j==2)cout<<sum1<<"ggdd"<<endl;
               if(sum1%9==0){
                   return true;
               }
           }
       }
       return false;
}
int32_t main()
{
    int test;
    cin>>test;
    while(test--){
       int n;
       cin>>n;
       int count2=0;
       int count3=0;
       int  sum=0;
       while(n!=0){
           if(n%10==2)count2++;
           if(n%10==3)count3++;
           sum+=n%10;
           n=n/10;
       }
       int req=9-(sum%9);
      if(fn(count2,count3,sum))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
       
       
        
    }

    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 2);

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

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

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

        a[i] -= t;

        a[i + 1] -= t;

        if(i > 1 && a[i] > a[i - 1] && a[i] > a[i + 1]) {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}

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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 2);

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

    if(n == 2) {

        int t = min(a[1], a[2]);

        a[1] -= t;

        a[2] -= t;

        if(a[1] > a[2]) {

            cout << "NO\n";

            return;

        }

    }

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

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

        a[i] -= t;

        a[i + 1] -= t;

        if(i > 1 && a[i] > a[i - 1] && a[i] > a[i + 1]) {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 2);

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

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

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

        a[i] -= t;

        a[i + 1] -= t;

        if(i > 1 && a[i] > a[i - 1] && a[i] > a[i + 1]) {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 2);

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

    if(n == 2) {

        int t = min(a[1], a[2]);

        a[1] -= t;

        a[2] -= t;

        if(a[1] > a[2]) {

            cout << "NO\n";

            return;

        }

    }

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

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

        a[i] -= t;

        a[i + 1] -= t;

        if(i > 1 && a[i] > a[i - 1] && a[i] > a[i + 1]) {

            cout << "NO\n";

            return;

        }

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}

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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 2, 0);

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

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

        if(a[i] < a[i - 1]) {

            cout << "NO\n";

            return;

        }

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

        a[i] -= t;

        a[i + 1] -= t;

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 2, 0);

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

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

        if(a[i] < a[i - 1]) {

            cout << "NO\n";

            return;

        }

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

        a[i] -= t;

        a[i + 1] -= t;

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}

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

using namespace std;

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

#define pb push_back

#define pob pop_back

#define mem(a, b) memset(a, b, sizeof(a));

#define int long long

typedef pair<int, double> pid;

typedef pair<double, int> pdi;

typedef pair<double, double> pdd;

const int L = 1e3 + 9;

const int N = 3e7 + 5;

const int M = 2e5 + 5;

const int Linf = 0x3f3f3f3f3f3f3f3f;

const int INF = 0x3f3f3f3f;

const int mod = 1e9 + 7;

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

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



void solve() {

    int n;

    cin >> n;

    vector<int> a(n + 5, 0);

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

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

        if(a[i] < a[i - 1]) {

            cout << "NO\n";

            return;

        }

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

        a[i] -= t;

        a[i + 1] -= t;

    }

    cout << "YES\n";

    return;

}



signed main() {

    ios;

    int T = 1;

    cin >> T;

    while (T--) solve();

    return 0;

}