Help me in solving DISJOINTSUB problem

My issue

how to approach to this problem?? like how can i think of something like this??

My code

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define forn(i, a, b) for (auto i = a; i < b; i++)

void solve()
{
    ll n; cin>>n;
    vector<ll>v(n);
    forn(i,0,n) cin>>v[i];
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Problem Link: Disjoint Non-Decreasing Array Practice Coding Problem - CodeChef

@sumit_gupta_05
here plzz refer my c++ code

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    int xmin=0;
	    int xmax=INT_MAX;
	    int ch=0,prev=-1;
	    for(int i=1;i<n;i++)
	    {
	        if(a[i]<a[i-1])
	        {
	            if(prev==-1)
	            {
	                prev=i;
	                xmin=max(xmin,a[i-1]-a[i]);
	                if(i!=n-1)
	                {
	                    xmax=min(a[i+1]-a[i],xmax);
	                }
	                i++;
	            }
	            else
	            {
	                if(a[i]<a[prev])
	                {
	                    ch=1;
	                    break;
	                }
	                else
	                {
    	                prev=i;
    	                xmin=max(xmin,a[i-1]-a[i]);
    	                if(i!=n-1)
    	                {
    	                    xmax=min(a[i+1]-a[i],xmax);
    	                }
    	                i++;
	                }
	            }
	        }
	    }
	    if(ch==1||xmax<xmin)
	    cout<<"NO";
	    else
	    cout<<"YES";
	    cout<<endl;
	}
	return 0;
}