class Solution
{
public:
int magicTower(vector<int>& nums)
{
//先判断一下有没有解
int sum = 0;
for(auto e:nums) sum += e;
if(sum < 0) return -1;
int res = 0;//结果
int hp = 1;//血线
priority_queue<int> pq;//大根堆
for(auto e:nums)
{
if(e < 0) pq.push(-e);
hp += e;
if(hp < 1)
{
//这意味着 e < 0,前面会把 e 入堆
hp += pq.top();//之前扣得最多的血加回来
pq.pop();
res ++;
}
}
return res;
}
};