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 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;





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

                    vec[i]=temp;

                    vec[i-1]=temp2;

                }

                else{

                    

                    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;

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

                        vec[i]=temp6;

                        vec[i+1]=temp4;

                        vec[i-1]=temp5;

                    }

                    else {

                        isPossibel=false;

                        break;

                    }

                }

                

            }

            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;

            }

        }



        if(isPossibel){

            cout<<"YES"<<endl;

        }

        else {

            cout<<"NO"<<endl;

        }



        

    }



    return 0;



};



Submission (verdict: Wrong answer on test 2):
#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;





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

                    vec[i]=temp;

                    vec[i-1]=temp2;

                }

                else{

                    

                    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;

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

                        vec[i]=temp6;

                        vec[i+1]=temp4;

                        vec[i-1]=temp5;

                    }

                    else {

                        isPossibel=false;

                        break;

                    }

                }

                

            }

            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;

            }

        }



        if(isPossibel){

            cout<<"YES"<<endl;

        }

        else {

            cout<<"NO"<<endl;

        }



        

    }



    return 0;



};