Codeforces Round #723 Potions (Hard/Easy) Solution (Java/C++)

Solution:

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.

Code:

Java

Submission #117684948 - Codeforces
Codeforces. Programming competitions and contests, programming community

C++

Submission #117726121 - Codeforces
Codeforces. Programming competitions and contests, programming community
Show Comments
DigitalOcean Referral Badge