Problem D
Geezer Scripts
The other day Unnar was playing the video game Geezer Scripts, Geezer Scripts V to be precise. He opened a door (in the game) and before he knew he was in a large and complicated cave-system, full of enemies who will attack as soon as Unnar gets to close to them. What’s worse is that the game doesn’t remember which enemies the player has already defeated so if the player leaves and comes back again the enemy will have respawned. Since Unnar is quite prone to getting lost he needs your help to find a way through the cave which incurs minimal damage to him.
Unnar’s character has some
The cave-system is not evenly elevated so its passages are
one-way. The cave-system can be modelled using
Input
The first line of the input contains two integers
Output
If Unnar can’t get through the cave-system output ‘Oh no’, without the quotes. Otherwise output the maximum health Unnar can have after getting through the cave-system.
Sample Input 1 | Sample Output 1 |
---|---|
1 2 3 2 1 2 1 2 2 3 1 2 |
Oh no |
Sample Input 2 | Sample Output 2 |
---|---|
1 3 3 2 1 2 1 2 2 3 1 2 |
1 |
Sample Input 3 | Sample Output 3 |
---|---|
5 20 5 6 1 2 10 6 1 3 2 15 1 4 1 33 2 5 1 7 3 4 1000 5 4 2 5 9 |
10 |