minggong @ 2020-02-19 21:15:48
#include<stdio.h>
int main()
{
int n,s,a,b,x[5000],y[5000],i,j,c=0;
scanf("%d %d",&n,&s);//苹果、力气
scanf("%d %d",&a,&b);//椅子、伸手
for(i=1;i<=n;i++)
scanf("%d %d",&x[i],&y[i]);//高度、力气
for(i=1;i<=n;i++)
{
if((a+b)>=x[i]&&s-y[i]>=0)
{
s=s-y[i];
if(s>=0)
c++;
else
break;
}
}
printf("%d",c);
return 0;
}
by 毕瑞成 @ 2020-02-19 21:20:49
显然应该优先选择花费力气小的进行摘取,这样才能保证摘得最多(贪心) 可以试试排序
by environmentalist @ 2020-02-19 21:23:17
先sort啊
by minggong @ 2020-02-19 21:27:44
见笑了,大佬们,我说这题怎么可能这么简单,哈