标签:type algorithm top 最大 贪心 node 遇到 iostream clu
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int maxm=150007;
int n;
struct node
{
ll t,ed;
bool operator < (const node &s) const
{
return ed<s.ed;
}
}a[maxm];
priority_queue<ll>q;
ll k=1;
int ans;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld%lld",&a[i].t,&a[i].ed);
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)
{
if(k+a[i].t>a[i].ed)
{
if(a[i].t<q.top())//找之前最大的且小于这个值的进行替换
{
k-=q.top();
q.pop();
k+=a[i].t;
q.push(a[i].t);
}
}
else
{
k+=a[i].t;
ans++;
q.push(a[i].t);
}
}
printf("%d\n",ans);
return 0;
}
标签:type algorithm top 最大 贪心 node 遇到 iostream clu
原文地址:https://www.cnblogs.com/lihan123/p/11674069.html