Limits
1s, 512 MB

You all may hear about the USS (United States of Santosh). There is an office in the USS that consist of $10^5$ floors. The name of that office is USS-Economic Office.

Nafisa is an employee of the USS Economic Office. Her apartment is located on $X^{th}$ floor and she needs to go to the $Y^{th}$ floor using the elevator. There's only one elevator in this office.

The initial position of the elevator is $A_1$. The elevator takes 1 unit of time to move from one floor to another (upward or downward). For example, it will take 3 unites of time to move from 3rd floor to 6th floor.

If $A_i$ $<$ $A_{i+1}$ then the elevator is moving upward.

if $A_i$ $>$ $A_{i+1}$ then the elevator is moving downward.

While moving the elevator, it will open its door on each floor, and the time required for this is so small that we can omit it.

Someone has accidentally pressed $n$ buttons on the elevator $(A_1, A_2, A_3, … , A_n)$. Now the buttons have stopped working. So Nafisa cannot press any more buttons, she can not change the order either. So it will carry out the pressed sequence only. So the lift will move from floor $A_1$ to floor $A_2$, and then from floor $A_2$ to floor $A_3$ and so on.

Now,

If $X^{th}$ floor lies between $A_i$ and $A_{i+1}$(inclusive) then It will take her from $X^{th}$ floor.

If $Y^{th}$ floor lies between $A_i$ and $A_{i+1}$(inclusive) and Nafisa already in the elevator then it will leave her to the $Y^{th}$ floor.

You can assume it takes 0 units of time to get on and off the elevator.

You have to find out if it is possible to reach the $Y^{th}$ floor. If it is possible then what is the time required to reach the $Y^{th}$ floor?

NOTE: **You can assume that the time starts when the elevator starts moving from the initial floor and Nafisa has been waiting on the** $X^{th}$ **floor from the beginning of the time.**

Input will contain $n$ ($2$ $\leq$ $n$ $\leq$$10^4$), which is the number of calls that someone accidentally pressed.

The next line will be a sequence of $n$ number of floors $A_i$, $A_{i+1}$, $A_{i+2}$….., $A_{n}$($1$ $\leq$ $A_i$ $\leq$$10^5$).

The next line will be $X$ and $Y$, where $X$ is Nafisa's floor and $Y$ is the floor that she wants to reach.

If Nafisa can reach $Y^{th}$ floor from $X^{th}$ floor then print YES and the time required to reach $Y^{th}$ floor.

Otherwise, print NO.

Input | Output |
---|---|

5 2 7 3 5 10 4 2 | NO |

Here $X$ is 4 $Y$ is $2$. While moving from $2^{nd}$ floor to $7^{th}$ floor Nafisa will get into the elevator but after that, the elevator does not reach $Y^{th}$floor. So the answer is NO. |

Input | Output |
---|---|

5 5 12 3 7 4 4 3 | YES 16 |

Here $X$ is $4$ and $Y$ is $3$. While moving the elevator from the $12^{th}$ floor to the $3^{rd}$ floor Nafisa will get into the elevator and after that as soon as the elevator reaches to $3^{rd}$ floor she will get off. |

Input | Output |
---|---|

2 1 10 3 4 | YES 3 |

Input | Output |
---|---|

2 1 15 4 3 | NO |

Login to submit.

76%
Solution Ratio

ToooonmoyEarliest,

HilariaFastest, 0.0s

MursaleenLightest, 5.7 MB

fahimcp495Shortest, 847B

Toph uses cookies. By continuing you agree to our Cookie Policy.