The Prince's Path
Premium Content - Free Preview
Challenge created by conioh
Note the clarification below
The Prince of Zakarta has a problem. The princess has been kidnapped by the demon. To save the princess he needs to travel through a path similar to figure below, where each line leads to different cities denoted by circles.
At most cities he faces two paths to two different cities. But in the bottom row, there's only one path forward to the end.
In each city the Prince will either find a devil power or good power. The Prince will initially start with the power of the first city he visits. If he passes the city with devil power
d then his power will be reduced by
d i.e. P - d. Similarly, if he passes the city with good power
g his power will be increased by
g i.e. P + g.
If, after the first city, his power ever becomes 0 or less, he will Die. The Prince has all the information needed, but he needs your help to tell him whether he can save the Princess.
End of Free Content Preview. Please Sign in or Sign up to buy premium content.
Egor KulikovMay 26, 10:13 AM
"The Prince will initially start with power P." It is not given in itput. What its value?
LearnerooMay 26, 10:26 AM
@Egor, he will start with the power of the first city he visits. Sorry for the confusion.
Fred SpielerMay 26, 1:19 PM
The first line of input contains the number of test cases... kind of matters...
Fred SpielerMay 26, 1:39 PM
Hmm... I pass the test input but not contest input... possibly something wrong with this problem?
LearnerooMay 26, 1:41 PM
Sorry, the challenge has been clarified, see above. Next time you're hired as reviewers!
James SmithMay 26, 11:15 PM
So wait, can he start from only the top-left city at (0, 0)? Or could he start at any city on the left side?
LearnerooMay 26, 11:17 PM
@James, he can start any city on the left side, as shown in the picture on top.