思路:
这位大爷只能往前走不能往回走所以从大到小排个序让他不能往回走,然后利用贪心,能AK就++,不能就输出AK的数量。
结构体排序模板(从小到大)
struct cwh
{ll pc,tt;}a[10000001];
bool pc(cwh x,cwh y)
{return x.pc<y.pc;}
sort(a+1,a+1+n,pc);
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll n,m,ans,num;
struct cwh
{
ll pc, tt;
}a[10000000];
bool pc(cwh x,cwh y)
{
return x.pc<y.pc;
}
int main()
{
scanf("%lld%lld",&n,&m);
for(ll i=1;i<=n;i++)
scanf("%lld%lld",&a[i].pc,&a[i].tt);
sort(a+1,a+1+n,pc);
ans=0;
for(ll i=1;i<=n;i++)
{
if(ans+a[i].pc>m)
{
printf("%lld",num);
return 0;
}
else ans+=a[i].tt;
num++;
}
return 0;
}