Problem library

Health Bar

Easy
simulation

A character starts with start health and can never go below 0 or above max.

Each number in events is applied in order: positive numbers heal, negative numbers deal damage. Once health reaches 0 the character is knocked out and later events are ignored.

Return the final health.

Examples

Input: start = 50, max = 100, events = [30,40,-20]
Output: 80
Input: start = 10, max = 100, events = [-15,50]
Output: 0