又是一道反悔贪心,怎么还是不会写呢!!哎
但是这样不好实现,需要反悔的贪心了
我们用优先队列来实现
#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
typedef long long ll;
ll n,m;
struct p{
ll x,t;
bool operator < (const p&tmp ) const{
return x<tmp.x;
}
}a[maxn];
priority_queue<ll>q;
int main()
{
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i].x >> a[i].t;
ll ans=0,last=0,temp=0;
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
{
m-=( a[i].x-last+a[i].t );//一路全都AC
temp++;
q.push( a[i].t );
while( m<0&&!q.empty() )//只要不能AK就一直弹出来
{
ll now=q.top(); q.pop();
temp--,m+=now;//AC数减少,但时间增加
}
if( m<0) break;//走都走不到
last=a[i].x;
ans=max(ans,temp);
}
cout<<ans;
}