classSolution { public: intmagicTower(vector<int>& nums){ longlong sum = 0; for (int i = 0; i < nums.size(); ++i) sum += nums[i]; if (sum < 0) return-1;
sum = 0; int cnt = 0; priority_queue<int, vector<int>, greater<int>> heap; for (int i = 0; i < nums.size(); ++i) { sum += nums[i]; if (nums[i] < 0) heap.push(nums[i]); while (sum < 0 && heap.size()) { cnt ++; nums.push_back(heap.top()); sum -= heap.top(); //cout << sum << ' ' << heap.top()<< endl; heap.pop(); } }