magicTower(nums[0..n-1], hp){ declare a empty max heap, named heap. ans := 0 for num in nums; do if num < 0; then heap.push(num) // push the negative number into the heap, so that we can recover the choice later if needed fi hp += num if hp <= 0; then if heap.isEmpty(); then //cannot recover return -1 fi ans++ hp -= heap.pop() // recover the smallest negative number, namely the most costly choice fi end return ans }