//优先队列
//priority_queue<Type, Container, Functional>
//类型,容器(vector,deque不能用list),实现功能
//priority_queue<int,vector<int>,less<int>>q----等同于----priority_queue<int>q;降序
//priority_queue<int,vector,greater<int>>q;升序
```cpp
1526C1
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6 + 5;
priority_queue<int>q;
int main()
{
int n;
cin >> n;
ll sum = 0,ans=0;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
sum += x;
ans++;
if (x < 0)q.push(abs(x));
if (sum < 0)
{
ans--;
sum += q.top();
q.pop();
}
}
cout << ans;
return 0;
}
优先队列priority-queue<int>q
最新推荐文章于 2023-04-24 17:42:39 发布