First, if there are not any limitations, we will drink all the potions. In fact, the only limitation is the health must not less than 0.
Then when the health is less than zero? Obviously, if and only if the sum of "good" potions is smaller than the sum of "bad" potions.
So, after drink the i-th potion, if the health is less than 0, then we spit out some bad potions, and we spit the worst potion first. And we keep spiting until the health is non-negative.