Woburn Challenge 2018-19 Round 4 - Senior Division
Billy has been having a great time playing a demo of Nintendo's next highly-anticipated 3D platforming game, Super Luigi Odyssey.
One challenge in the game sees Luigi trapped in a long hallway, which
can be represented as a number line with positions increasing towards
the rightwards direction. There are
Much to Luigi's concern, the hallway is filled with some deadly lava.
Initially, the lava reaches up to a height of
A sequence of
- If
, then the lava's height will increase by metres. It's guaranteed that this will not cause the lava's height to become negative. If this causes Luigi's current platform to become submerged, then he will immediately perish. - If
, then lasers in a row will be fired at Luigi. Each laser will force him to jump to the next non-submerged platform to the left of his current one. If there's no such platform, then he'll instead be forced to jump into the lava and perish. - If
, then similarly lasers in a row will be fired at Luigi, with each one forcing him to jump to the next non-submerged platform (if any) to the right rather than the left.
Luigi is not allowed to move between platforms aside from being forced
to by type-
Even if Billy manages to keep Luigi alive through all
Help Billy determine how much energy Luigi will expend throughout all
Subtasks
In test cases worth
In test cases worth another
Input Specification
The first line of input consists of three space-separated integers,
Output Specification
Output a single integer, the total number of units of energy which Luigi
will expend (modulo -1
if he will be forced to touch
the lava and perish at any point.
Sample Input 1
5 7 1
4 4
5 5
13 6
0 8
10 8
3 1
1 4
2 1
1 -1
3 4
1 2
2 2
Sample Output 1
32
Sample Input 2
2 2 2
0 2
1 1
1 1
3 1
Sample Output 2
-1
Sample Explanation
In the first case, Luigi will be forced to jump along the following sequence of positions:
- Event 1:
- Event 3:
- Event 5:
- Event 7:
In total, these jumps require
In the second case, after the lava's height is raised to
Comments