Find the fewest moves to go from building S to D, where each move jumps F forward or B backward, avoiding police buildings.
Medium4BFSGraphNo attempts yetTime limit1sMemory limit512 MBA new game has arrived at an arcade near Hongik University. You play the master thief X of Mapo-gu, who has just robbed a jewelry store, and you clear the game by getting X home without being seen by anyone. The game uses only two buttons, left and right, and follows these rules.
The game is still in beta, so it has bugs where there is no way to get home safely.
Jiun's hobby is clearing arcade games faster than anyone else. So among all the ways X can reach home safely, Jiun wants the smallest number of left and right button presses.
You are given the number of buildings N, the robbed jewelry store S, X's home D, the number of buildings F covered by one forward run, the number of buildings B covered by one backward run, the number of police stations K, and the building numbers of the police stations l1,l2,…,lK. Write a program that prints the minimum number of button presses X needs to reach home safely.
If you find a case with no way home, print BUG FOUND so the data can be reported to the game company.
The first line contains N, S, D, F, B, and K. If K>0, the second line contains the police station positions l1,l2,…,lK.
Print on the first line the minimum number of button presses Jiun needs so that X gets from building S to his home D safely. If D cannot be reached, print BUG FOUND.