Can't Understand

Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs.

The stairs are at an angle of 45 degrees and Chef’s velocity is V1 m/s when taking the stairs down. The elevator on the other hand moves with a velocity V2 m/s. Whenever an elevator is called, it always starts from ground floor and goes to N-th floor where it collects Chef (collecting takes no time), it then makes its way down to the ground floor with Chef in it.

The elevator cross a total distance equal to N meters when going from N-th floor to ground floor or vice versa, while the length of the stairs is sqrt(2) * N because the stairs is at angle 45 degrees.
Chef has enlisted your help to decide whether he should use stairs or the elevator to minimize his travel time. Can you help him out?
In this problem Why we use 2*N for Elevator distance ?

Chef wants to come down to ground floor from n-th floor (e.g. 2nd, 3rd etc.).
He has two options, either to take stairs or elevator.
The velocity of chef is given v1 and that of elevator is v2.
If he chooses elevator, the elevator is in the ground floor to so it first goes to nth floor picks up chef and comes back to ground floor.
If he chooses stairs then stairs are at an angle of 45 degree so the distance by stairs is square root of 2 multiplied by n.

Now use simple distance-time-speed formula to calculate the minimum time.

1 Like

we use 2*t because the elevator is present at the ground floor you call it , it will go up and then come down , so 2t
while via stairs you need to get down only.

1 Like

please upvote , i am new

Did you figure out how to do it? I’ve done t1=(sqrt(2)N)/V1, t2=2(N/V2), if (t1>t2) cout>>“Stairs” ;, else if (t2>t1) cout<<“Elevator”; but I keep getting testcase mismatch for some of the inputs.