Woburn Challenge 2018-19 Round 4 - Junior Division
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 \le N \le 100)~ events will occur, the ~i~-th of which will cause Mario's HP to increase by ~H_i~ ~(-100 \le H_i \le 100, H_i \ne 0)~. Note that ~H_i~ 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, ~H_i~, for ~i = 1 \dots N~.
Output a single integer, the number of Life Shrooms which Mario will consume.
6 -30 -20 50 -59 1 -10
- After the ~1~-st event, Mario's HP will drop to ~20~.
- After the ~2-~nd event, Mario's HP will drop to ~0~, causing him to consume a Life Shroom and have his HP restored to ~10~.
- After the ~3~-rd event, Mario's HP will increase to the limit of ~50~.
- After the ~4~-th event, Mario's HP will drop below ~0~, resulting in the consumption of another Life Shroom.
- After the ~5~-th event, Mario's HP will increase to ~11~.
- After the ~6~-th event, Mario's HP will drop to ~1~.
Overall, Mario will have consumed ~2~ Life Shrooms (after the ~2~-nd and ~4~-th events).