Please help me in HILLS from this lunchtime.

hills
problem in this question getting a wrong anawer

#include<iostream>
using namespace std;
int main()
{ int t;
	cin>>t;
	while(t--)
	{
		long n,u,d,s=1,c=1;
		
		cin>>n>>u>>d;
		long a[n];
			for(int i=0;i<n;i++)
	
				cin>>a[i];
		for(int i=0;i<n;i++)
		{
			
			if((a[i+1]-a[i])<=u&&(a[i+1]-a[i])>=0)
			 c++;
			else if((a[i]-a[i+1])<=d)
			 c++;
			else if((a[i]-a[i+1])>d&&(a[i]-a[i+1])>=0)
			 {  if(s==1)
			   {c++;s=0;
			   }
			 	
			 }
			 
			 else 
			 break;
			 
			
		}
		cout<<c<<endl;
		
		
		
		
	}
	return 0;
	
	
}

Why my this submission for HILLS (see CodeChef: Practical coding for everyone ) is not working?

@lemonstudy -

You are not taking the complete input. Eg- For N=1 case which you handled separately, you did not take in the given array value as input, which in turn got taken as your next N value in next iteration. Please take the complete input and try again. Failing case-

Input
3
1 10 10
1
2 5 1
1 7
2 5 1
7 1
Your Output
1
1
1
Expected Output
1
1
2

@saini30 - You fail even at sample input output. Firstly - else if((a[i]-a[i+1])<=d) add a check that a[i]\ge a[i+1] because the condition above it can fail even when a[i]\le a[i+1]

What is happening is, your code doesnt stop if height of next hill is more than U. it goes to else if((a[i]-a[i+1])<=d) this condition and increases c if this one satisfies.