Woburn Challenge 2018-19 Round 4 - Junior Division
Problem 2: Life Insurance
Today, Billy feels the need to unwind by returning to one of his favourite video games, the classic role-playing game Paper Mario. There's nothing more satisfying than replaying the final boss battle against Bowser!
When in battle, Mario's current health is represented by an integral "HP" value. His HP begins at 50, and may increase or decrease over the course of the battle.
While battling against Bowser, a sequence of N (1 ≤ N ≤ 100) events will occur, the i-th of which will cause Mario's HP to increase by Hi (−100 ≤ Hi ≤ 100, Hi ≠ 0). Note that Hi may either be negative (indicating an attack by Bowser) or positive (indicating a healing item used by Mario). If an event would cause Mario's HP to become greater than 50, it instead becomes equal to exactly 50. On the other hand, if an event would cause Mario's HP to become less than or equal to 0, then let's just say that our hero's in trouble!
However, Billy has planned against such an eventuality, by stocking Mario up on an abundance of Life Shroom items. When Mario's HP becomes less than or equal to 0, he automatically consumes a Life Shroom, which restores his HP and causes it to become equal to 10 instead!
Assuming that Mario will never run out of Life Shrooms, help Billy determine how many of them Mario will consume over the course of the entire battle.
The first line of input consists of a single integer, N.
N lines follow, the i-th of which consists of a single integer, Hi, for i = 1..N.
Output a single integer, the number of Life Shrooms which Mario will consume.
6 -30 -20 50 -59 1 -10
- After the 1st event, Mario's HP will drop to 20.
- After the 2nd event, Mario's HP will drop to 0, causing him to consume a Life Shroom and have his HP restored to 10.
- After the 3rd event, Mario's HP will increase to the limit of 50.
- After the 4th event, Mario's HP will drop below 0, resulting in the consumption of another Life Shroom.
- After the 5th event, Mario's HP will increase to 11.
- After the 6th event, Mario's HP will drop to 1.
Overall, Mario will have consumed 2 Life Shrooms (after the 2nd and 4th events).
Point Value: 5 (partial)
Time Limit: 2.00s
Memory Limit: 16M
Added: Mar 22, 2019
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3