Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Compilation error):


     

     

     #include <bits/stdc++.h>

using namespace std;

#define ld long double

#define ll long long

#define ull unsigned long long

#define umpp map<ll,ll> 

#define nin int n; cin >> n;

#define nil ll n; cin >> n;

#define open ifstream inputFile("input.txt");ofstream outputFile("output.txt");if(!inputFile){ cerr << "Error opening input file!" << endl;return 1;}if (!outputFile){cerr << "Error opening output file!" << endl;return 1; }cin.rdbuf(inputFile.rdbuf());cout.rdbuf(outputFile.rdbuf());

#define tit int t = 1; cin >> t;

#define til ll t = 1; cin >> t;

#define vvl vector<vector<ll>>

#define vi vector<int>

#define vvi vector<vi>

#define art ios::sync_with_stdio(false);

#define by cin.tie(0);

#define ayush cout.tie(NULL);

#define vb vector<bool>

#define TIME cout<<(double)clock()/CLOCKS_PER_SEC <<"ms"<<endl;

#define pray inputFile.close(); outputFile.close();

#define vl vector<long long>

#define vp vector<pair<long long,long long>>

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

#define srt(v) sort(v.begin(), v.end())      

#define mxe(v) *max_element(v.begin(), v.end()) 

#define mne(v) *min_element(v.begin(), v.end()) 

#define unq(v) v.resize(distance(v.begin(), unique(v.begin(), v.end()))); 

#define uq(b) b.erase(unique(b.begin(),b.end()),b.end());

#define chk(x,y) count(x.begin(), x.end(), y);

// make sure to sort before applying unique // else only consecutive duplicates would be removed

#define yes {cout << "YES\n";return ;}

#define no {cout << "NO\n";return ;}

#define f0(lcv, hi) for (int lcv = 0; lcv < hi; lcv++)

#define fb(lcv, hi) for (int lcv = hi; lcv >= 0; lcv--)

#define f1(lcv, hi) for (int lcv = 1; lcv <= hi; lcv++)

#define pisec(u) sort(u.begin(), u.end(), [](auto &left, auto &right) {return left.second <right.second;});



bool ckck(ld xi,ld yi,ld xj,ld yj,ld x1,ld y1){

    return ((yj-yi)*(x1-xi)==(y1-yi)*(xj-xi)&&x1>=min(xi,xj)&&x1<=max(xi,xj)&&y1>=min(yj,yi)&&y1<=max(yj,yi));

}



ll inside(ll n,ld *x,ld *y,ld x1,ld y1){

    ll i,j,c=0;

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

        //if(ckck(x[i],y[i],x[j],y[j],x1,y1))return 1;

        if(((y[i]>y1)!=(y[j]>y1))&&(x1<(x[j]-x[i])*(y1-y[i])/(y[j]-y[i])+x[i]))c=!c;

    }

    //c==1,point is inside else it is not

    return c;

}

long long constructPalindrome(int num, bool odd) {

    long long rev = num, temp = odd ? num / 10 : num;  

    while (temp > 0) {

        rev = rev * 10 + (temp % 10);

        temp /= 10;

    }

    return rev;

}



vector<ll> palindromestillN(int n) {

    vector<ll> palindromes;

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

        if (i > n) break;

        palindromes.push_back(i);

    }

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

        long long oddPalindrome = constructPalindrome(i, true);

        if (oddPalindrome <= n) palindromes.push_back(oddPalindrome); 



        long long evenPalindrome = constructPalindrome(i, false);

        if (evenPalindrome <= n) palindromes.push_back(evenPalindrome);

    }



    return palindromes;

}

int upper(vector<ll>& a,int i,int j,int t)

{

    int ans=-1 ;

    while(i<=j)

    {

        int md=i+ (j-i)/2 ;

        if(a[md]<=t)

        {

            ans=md;i=md+1;

        }else j=md-1 ;

    }

    return ans==-1?a.size():ans ;

}

struct custom_hash {

 static uint64_t splitmix64(uint64_t x) {

  x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;

  return x ^ (x >> 31);

 }

 size_t operator()(uint64_t x) const {

  static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

  return splitmix64(x + FIXED_RANDOM);

 }

};

class SegmentTree {

public:

    int n;

    vector<int> tree;



    // Constructor that takes the input vector

    SegmentTree(const vector<int>& arr) {

        n = arr.size();

        // Initialize the tree vector with a size of 4 * n (maximum size for segment tree)

        tree.resize(4 * n);

        build(arr, 0, 0, n - 1);

    }

    void build(const vector<int>& arr, int node, int start, int end) {

        if (start == end) {

            tree[node] = arr[start];

        } else {

            int mid = start + (end - start) / 2;

            int leftChild = 2 * node + 1;

            int rightChild = 2 * node + 2;

            build(arr, leftChild, start, mid);

            build(arr, rightChild, mid + 1, end);

            tree[node] = tree[leftChild] + tree[rightChild];

        }

    }



    void update(int idx, int val) {

        update(0, 0, n - 1, idx, val);

    }



    void update(int node, int start, int end, int idx, int val) {

        if (start == end) {

            tree[node] = val;

        } else {

            int mid = start + (end - start) / 2;

            int leftChild = 2 * node + 1;

            int rightChild = 2 * node + 2;

            if (idx >= start && idx <= mid) {

                update(leftChild, start, mid, idx, val);

            } else {

                update(rightChild, mid + 1, end, idx, val);

            }

            tree[node] = tree[leftChild] + tree[rightChild];

        }

    }



    int query(int s, int e) {

        return query(0, 0, n - 1, s, e);

    }



    int query(int node, int start, int end, int s, int e) {

        if (e < start || end < s) {

            return 0;

        }

        if (s <= start && end <= e) {

            return tree[node];

        }

        int mid = start + (end - start) / 2;

        int leftChild = 2 * node + 1;

        int rightChild = 2 * node + 2;

        int leftQuery = query(leftChild, start, mid, s, e);

        int rightQuery = query(rightChild, mid + 1, end, s, e);

        return leftQuery + rightQuery;

    }

};

double tolBinarySearch(const double initial_lo,const double initial_hi)

{

    double lo = initial_lo; // Set initial lower bound

double hi = initial_hi; // Set initial upper bound



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

    double mid = (lo + hi) / 2.0;

    if (mid==0) lo = mid; else hi = mid;

}

double answer = (lo + hi) / 2.0;

return answer ;

}

int binarySearch(const vector<int>& arr, int target) {

    int left = 0, right = arr.size() - 1;

    while (left <= right) {

        int mid = left + (right - left) / 2;

        if (arr[mid] == target)

            return mid;

        if (arr[mid] < target)

            left = mid + 1;

        else

            right = mid - 1;

    }

    return -1; 

}



// Function to calculate modular exponentiation (Modular Exponentiation)

// Computes (base^exp) % mod efficiently.

int modExp(long base, long exp, long mod) {

    int result = 1;

    base = base % mod;

    while (exp > 0) {

        if (exp & 1)

            result = (result * base) % mod;

        exp >>= 1;

        base = (base * base) % mod;

    }

    return result;

}

ll modExp(ll base, ll exp) {

   ll result = 1;

    while (exp > 0) {

        if (exp & 1)

            result = (result * base) ;

        exp >>= 1;

        base = (base * base) ;

    }

    return result;

}

 int gcd(int a, int b)

    {

        if (a == 0)

            return b; 

        return gcd(b % a, a); 

    }

 int lcm(int a, int b){ return (a / gcd(a, b)) * b;}





 const int MOD = 1e9 + 7;

vector<long long> fact, inv_fact; 



long long power(long long x, int y, int p) {

    long long res = 1;

    x = x % p;

    while (y > 0) {

        if (y & 1)

            res = (res * x) % p;

        y >>= 1;

        x = (x * x) % p;

    }

    return res;

}



void compute_factorials(int max_n) {

    fact.resize(max_n + 1);

    inv_fact.resize(max_n + 1);

        fact[0] = 1;

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

        fact[i] = fact[i - 1] * i % MOD;

    }

        inv_fact[max_n] = power(fact[max_n], MOD - 2, MOD);

    for (int i = max_n - 1; i >= 0; --i) {

        inv_fact[i] = inv_fact[i + 1] * (i + 1) % MOD;

    }

}





// Function to calculate modular inverse using Fermat's Little Theorem

long modInverse(long a, long mod) {   //consider precomputation for all invFacts till n

    // Fermat's Little Theorem: a^(mod-2) % mod is the modular inverse if mod is prime.

    return modExp(a, mod - 2, mod);

}



long modAdd(long a, long b, long mod) {

    return (a + b) % mod;

}



long modSub(long a, long b, long mod) {

    return (a - b + mod) % mod;

}



long modMul(long a, long b, long mod) {

    return (a * b) % mod;

}



long nCk(long n, long k, long p) {

    return ((fact[(int)n] * modInverse(fact[(int)k], p)) % p * modInverse(fact[(int)(n - k)], p)) % p;

}



int highestPowerof2(int n) {

    int p = static_cast<int>(log(n) / log(2));

    return static_cast<int>(pow(2, p));

}



int highestPowerof2bits(int x) {

    x |= x >> 1;

    x |= x >> 2;

    x |= x >> 4;

    x |= x >> 8;

    x |= x >> 16;

    return x ^ (x >> 1);

}

const int MAXN = 1e6 + 5;  // We only need primes up to sqrt(10^12)



// List of prime numbers

vector<int> primes;

bitset<MAXN> arePrime;



// **Step 1: Precompute all primes up to sqrt(10^12)**

void sieve() {

    arePrime.set();  // Set all numbers as prime initially

    arePrime[0] = arePrime[1] = 0;



    for (int i = 2; i < MAXN; i++) {

        if (arePrime[i]) {

            primes.push_back(i);

            for (ll j = 1LL * i * i; j < MAXN; j += i) {

                arePrime[j] = 0;

            }

        }

    }

}



// **Step 2: Efficient Prime Factorization for Large n**

vector<ll> primeFactorization(ll n) {

    vector<ll> factors;

    

    // **Trial division using precomputed primes**

    for (int p : primes) {

        if (1LL * p * p > n) break;  // Stop if p^2 > n

        

        while (n % p == 0) {

            factors.push_back(p);

            n /= p;

        }

    }



    // **If n is still greater than 1, it must be prime**

    if (n > 1) factors.push_back(n);



    return factors;

}

vector<int> findPrimeFactors(int n) {

    vector<int> factors;

    if (n % 2 == 0) {

        factors.push_back(2);

        while (n % 2 == 0) {

            n /= 2;

        }

    }

    for (int i = 3; i * i <= n; i += 2) {

        if (n % i == 0) {

            factors.push_back(i);

            while (n % i == 0) {

                n /= i;

            }

        }

    }

    if (n > 1) {

        factors.push_back(n);

    }



    return factors;

}

int largestMultipleLessThanN(int x, int n) {

    return (n - 1) / x * x; 

}





bool isPrime(ll n) {

    if (n <= 1ll)

        return false;

    if (n <= 3ll)

        return true;

    if (n % 2ll == 0 || n % 3ll == 0)

        return false;

    for (int i = 5ll; i * i <= n; i += 6ll) {

        if (n % i == 0 || n % (i + 2ll) == 0)

            return false;

    }

    return true;

}

vector<ll> getFactors(ll n) {

    vector<ll> factors;

    for (ll i = 1; i * i <= n; i++) {

        if (n % i == 0) {

            factors.push_back(i);

            if (i != n / i)  

                factors.push_back(n / i);

        }

    }

    return factors;

}

int greatestDivisorLessThanK(int n, int k) {

    int bestDivisor = 1; 



    for (int d = 1; d * d <= n; d++) {

        if (n % d == 0) {

            if (d < k) bestDivisor = max(bestDivisor, d);

            if (n / d < k) bestDivisor = max(bestDivisor, n / d);

        }

    }

    return bestDivisor;

}





const int MX_SZ = 1e5 + 5;

int par[MX_SZ];





void tests()

{

    nin

    vi a(n) ;

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

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

    {int m=min(a[i],a[i+1]) ;a[i]-=m ;a[i+1]-=m ;}

    bool t=true ;

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

    if(t){if(a[n-1]>=0)yes 

    no



     

     

   }

 

 

 int32_t main()

{art by ayush

// tit 

// open 

// while(t--)

     tests();  

//  pray

    return 0;

}