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

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

typedef long long ll;//1e18

#define fi first

#define se second

#define  pll pair<ll,ll>

#define MAXN 100005

#define pb push_back

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

#define ull unsigned long long//1e19

#define endl "\n"

#define ld long double

#define allc(x) x.begin(),x.end(),cmp

//cout<<fixed<<setprecision()<<ans<<endl;

using namespace std;

//struct

bool cmp(ll x,ll y){

return x>y;

}

const int N=2e6+10;

const int mod=1000000007;

//初始化

int s[MAXN];

int fa[MAXN];

int add(int n){

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

fa[i]=i;

s[i] = 1;

}

}

//查询 寻找祖先 进行路径压缩



int find (int i){

if(fa[i]==i){

return i;

}else{

fa[i]=find(fa[i]);

return fa[i];

}

}



//合并

void unionn(int i,int j){

int i_fa=find(i);

int j_fa=find(j);

if(i_fa!=j_fa){

if(s[i_fa] < s[j_fa]) {

fa[i_fa] = j_fa;

s[j_fa] += s[i_fa];

} else {

fa[j_fa] = i_fa;

s[i_fa] += s[j_fa];

}

}

}



// DFS



/*



ll p,q;

ll min=1e7;

ll m,n;

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

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

ll a[100][100]; // 1表示空地 2表示障碍物

ll v[100][100]; // 0表示未探索 1表示已经探索

void dfs(ll x,ll y,ll step){

if(x==p&&y==q){

if(step<min){

min=step;

return ;

}

}

//顺时针探索

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

ll tx,ty;

tx=x+dx[i];

ty=y+dy[i];

if(a[tx][ty]==1&&v[tx][ty]==0){

v[tx][ty]=1;

dfs(tx,ty,step+1);

v[tx][ty]=0;

}

}

}



*/



// 背包

// 快速幂

ll modpow(ll n,ll m,ll q){

ll result=1;

while(m>0){

if(m%2==1){

result=(result*n)%q;

}

n=(n*n)%q;

m/=2;

}

return result;

}

void solve(){

ll n;

cin>>n;

ll a[n+1];

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

cin>>a[i];

}

bool flag=0;

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

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

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

if(a[i+2]<a[i+1]||a[i]>a[i+1]){

flag=1;

}

}

if(flag){

cout<<"NO"<<endl;

}else{

cout<<"YES"<<endl;

}

}

int main(){

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

int t=1;

cin>>t;

while(t--){

solve();

}

return 0;

}









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

typedef long long ll;//1e18

#define fi first

#define se second

#define  pll pair<ll,ll>

#define MAXN 100005

#define pb push_back

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

#define ull unsigned long long//1e19

#define endl "\n"

#define ld long double

#define allc(x) x.begin(),x.end(),cmp

//cout<<fixed<<setprecision()<<ans<<endl;

using namespace std;

//struct

bool cmp(ll x,ll y){

return x>y;

}

const int N=2e6+10;

const int mod=1000000007;

//初始化

int s[MAXN];

int fa[MAXN];

int add(int n){

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

fa[i]=i;

s[i] = 1;

}

}

//查询 寻找祖先 进行路径压缩



int find (int i){

if(fa[i]==i){

return i;

}else{

fa[i]=find(fa[i]);

return fa[i];

}

}



//合并

void unionn(int i,int j){

int i_fa=find(i);

int j_fa=find(j);

if(i_fa!=j_fa){

if(s[i_fa] < s[j_fa]) {

fa[i_fa] = j_fa;

s[j_fa] += s[i_fa];

} else {

fa[j_fa] = i_fa;

s[i_fa] += s[j_fa];

}

}

}



// DFS



/*



ll p,q;

ll min=1e7;

ll m,n;

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

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

ll a[100][100]; // 1表示空地 2表示障碍物

ll v[100][100]; // 0表示未探索 1表示已经探索

void dfs(ll x,ll y,ll step){

if(x==p&&y==q){

if(step<min){

min=step;

return ;

}

}

//顺时针探索

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

ll tx,ty;

tx=x+dx[i];

ty=y+dy[i];

if(a[tx][ty]==1&&v[tx][ty]==0){

v[tx][ty]=1;

dfs(tx,ty,step+1);

v[tx][ty]=0;

}

}

}



*/



// 背包

// 快速幂

ll modpow(ll n,ll m,ll q){

ll result=1;

while(m>0){

if(m%2==1){

result=(result*n)%q;

}

n=(n*n)%q;

m/=2;

}

return result;

}

void solve(){

ll n;

cin>>n;

ll a[n+1];

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

cin>>a[i];

}

bool flag=0;

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

ll x=0;

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

a[i+1]=a[i+1]-x;

a[i]=a[i]-x;

if(a[i+2]<a[i+1]||a[i]>a[i+1]){

flag=1;

}

}

if(flag){

cout<<"NO"<<endl;

}else{

cout<<"YES"<<endl;

}

}

int main(){

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

int t=1;

cin>>t;

while(t--){

solve();

}

return 0;

}