maxDamage to 0 to keep track of the maximum damage from any level.totalDamage to 0 to keep track of the sum of all damages.d in the damage array.
totalDamage by adding d to it.maxDamage to be the maximum of maxDamage and d.min(armor, maxDamage).totalDamage to get the net damage.