Jumping in the hills getting wrong answer

i dont know i which case it is failing .Can you guys help me where am going wrong?

#include<iostream>
#include<cstdio>
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#include <vector>

using namespace std;

int main()
{
	FAST_IO

int T,N;
	long int U,D,H,jump,prev_H;
	cin>>T;
	while(T--)
	{
		jump=1;
		cin>>N>>U>>D;
		int para=1;
		vector<int>H(N);
		for(int i=0;i<N;i++)
		{
				cin>>H[i];
		}
	
		for(int i=0;i<N-1;i++)
		{
			if(H[i]<H[i+1])
			{
				if((H[i+1] - H[i]) <= U)
				{
					jump++;
				}
				else
					break;
			}	
			else if(H[i]>H[i+1])
			{
				if((H[i]-H[i+1] )<= D)
					jump++;
				else	
					{
						if(para == 1)
							{
								jump++;
								para=0;
							}
					}
			
			}
			else if(H[i] == H[i+1])
					jump++;
		
		
		}

		cout<<jump<<"\n";
		    }
		
		
		
		
		

    return 0;
}


At a guess: what happens if he needs a parachute, but doesn’t have one (much like the case where he needs to jump upwards by more than U)?

Edit:

Here’s a random failing testcase:

1
34 27 2
14 17 11 11 13 11 17 6 18 1 13 12 2 3 19 15 18 17 3 19 5 10 11 2 12 18 18 15 13 16 18 8 13 6 
1 Like

look at this point .

Chef can use a parachute and jump to a lower hill regardless of its height (as long as it’s lower than the current hill). This jump can only be performed at most once.

it means he has one parachute right?

Yes :slight_smile: So what happens if he needs a parachute, but doesn’t have one? :slight_smile:

he cant make a jump to lower hill .

if(para == 1)
{
	jump++;
	para=0;
}

this is the condition that i put for if he doesnt have a parachute.

I want to know the answer for the above case.
Thank you

The answer for the above testcase is 7, for the reason I’ve been hinting about :wink:

yeah now i got the point why am failing :blush:

1 Like