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

Solution 1 (runtime: 343 ms):
//see the intuition is, if you do ny operation at least one will become 0. 
//so your ideal array has to be of type 0 0 0 0 <> then unchanged
//now from left, you'd always want to do op, as anyway left one has to become zero

#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n;
    cin>>n;
    deque<int>dq;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        dq.push_back(x);
    }


bool flag = true;

    while(dq.size() > 1){//see the condition, perpetually doing it
        if(dq[0] > dq[1]){
            flag = false;
            break;
        }
        else if(dq[0] < dq[1]){
            dq[1]-=dq[0];
            dq.pop_front();
        }
        else{
            dq.pop_front();
            dq.pop_front();
        }
    }
    cout<< (flag == true ? "YES\n" : "NO\n");//bracket is necessary for ternary to work
}

using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

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

using namespace std;



#define ll long long int





ll mod_expo(ll a, ll b)

{

    if (b == 0)

        return 1;

    ll res = mod_expo(a, b / 2);

    res = res * res;

    if (b % 2 == 1)

        res = res * a;

    return res;

}



bool isPalindrome(vector<ll> &vec)

{

    // cout<<"hello"<<endl;

    int i = 0;

    int j = vec.size() - 1;

    while (i < j)

    {

        if (vec[i] != vec[j])

            return false;

        i++;

        j--;

    }

    return true;

}

vector<bool> SieveOfEratosthenes()

{

    vector<bool> prime(10000000 + 1, true);

    int n = 10000000;

    for (int p = 2; p * p <= n; p++)

    {

        if (prime[p] == true)

        {

            for (int i = p * p; i <= n; i += p)

                prime[i] = false;

        }

    }

    return prime;

}









int main()

{

    ll mod = 1e9 + 7;



    // question pdh lo sir

    // constraints bhi dhk lo sir

    // have trust on yourself ki jo tu kr rha hai best approach hai

    // dimag me test case lao aur ek baar uspr run krke dhklo sir



    // gcd of an array a[]={a,b,c,d} === gcd(a,b-a,c-a,d-a)

    // logic is simple and similar to gcd() of two no; i.e. gcd(a,b)=gcd(a,b-a);

    ll _;

    cin >> _;

    // vector<bool> prime=SieveOfEratosthenes();

    while (_--)

    {

        ll n;

        cin>>n;



        vector<ll> vec(n);

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

            cin>>vec[i];

        }

        bool isPossibel=true;



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

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

                isPossibel=false;

                break;

            }

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

                ll mini1=min(vec[i],vec[i-1]);

                ll temp=vec[i]-mini1;

                ll temp2=vec[i-1]-mini1;



                ll mini2=min(vec[i],vec[i+1]);

                ll temp3=vec[i]-mini2;

                ll temp4=vec[i+1]-mini2;



                ll mini=min(temp3,vec[i-1]);

                ll temp5=vec[i-1]-mini;

                ll temp6=temp3-mini;



                // cout<<temp3<<" "<<temp4<<" "<<temp5<<" "<<temp6<<endl; 

                if((temp6>=temp5 && temp6 <=temp4 )|| (temp6>=temp5 && temp6 <=temp4 )){

                    vec[i]=temp6;

                    vec[i+1]=temp4;

                    vec[i-1]=temp5;

                    continue;

                }



                if((temp<=vec[i+1] && temp>=temp2)  ||  (temp<=vec[i+1] && temp>=temp2)  ){

                    vec[i]=temp;

                    vec[i-1]=temp2;

                    continue;

                }

                        

                

            }

            else if(vec[i]<vec[i-1] && vec[i]<vec[i+1]){

                isPossibel=false;

                break;

            }

            else if(vec[i]>vec[i-1] && vec[i]<vec[i+1]){

                    vec[i+1]=vec[i+1]+vec[i-1] - vec[i];

                    vec[i]=0;

                    vec[i-1]=0;

            }

        }



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

            if(vec[i]>vec[i+1]){

                isPossibel=false;

                break;

            }

            // cout<<vec[i]<<" ";

        }

        // cout<<endl;





        if(isPossibel){

            cout<<"YES"<<endl;

        }

        else {

            cout<<"NO"<<endl;

        }



        

    }



    return 0;



};