1.2 Ryn Blackwood’s Adventure: Corridor of Echoes
Into the cave, Ryn Blackwood finds herself journeying through the forgotten catacombs beneath the ruins of Viserna. She comes upon a mysterious corridor called the Corridor of Echoes. This ancient hallway has n enchanted gates, numbered 1 to n, that Ryn must pass through in order to reach the Chamber of Secrets on the other side.
Each gate is either active or dormant. An active gate lets Ryn pass through effortlessly, costing her 1 second. However, a dormant gate cannot be passed through unless Ryn activates a timeless amulet she discovered earlier. The amulet can be used only once for the entirety of its time and when activated, it temporarily awakens all dormant gates, making them passable for x seconds before they return to their dormant state.
Ryn must decide when to use the amulet so that she can pass through all the gates in order. Given the inputs, can Ryn make it to the Chamber of Secrets?
Constraints
Input Format
First Line- n and x signifying number of gates and the amulet time
Second Line- n space separated values consisting of 0 and 1, 1 signifying dormant door and 0 signifying active door
Output Format
String “YES” if Ryn can pass all n gates, otherwise “NO”
Example 1
Input:
6 3
0 0 1 0 0 1
Output:
NO
Explanation:
Even if Ryn activates the amulet at the 3rd gate, which is dormant, Ryn can’t pass the 6th gate with it.
Example 2
Input:
7 4
0 0 0 1 0 1 1
Output:
YES
Explanation:
Ryn can activate the amulet on the 4th gate which is dormant and can pass through all remaining gates successfully.
Log In to solve the Question