flysky @ 2020-02-06 14:31:09
#include<stdio.h>
int main()
{
int n,s,a,b,c,index=0,i,x[5005],y[5005],z[5005],e=0,j,d;
scanf("%d%d",&n,&s);
scanf("%d%d",&a,&b);
for(i=0;i<n;i++)
{
scanf("%d%d",&x[i],&y[i]);
}
for(i=0;i<n;i++)
{
if(a+b>=x[i])
{
c=index;
z[index++]=y[i];
}
}
for(i=0;i<c;i++)
{
for(j=i;j<c;j++)
{
if(z[i]>z[j])
{
d=z[j];
z[j]=z[i];
z[i]=d;
}
}
}
for(i=0;i<c;i++)
{
e=e+z[i];
if(e>s)
{
printf("%d",i);
break;
}
}
return 0;
}
by woshizhazha @ 2020-02-07 14:43:25
是输入格式有误吗?
by woshizhazha @ 2020-02-07 14:46:03
你试试输入 0 0 0 0 看输出是不是0
by Itachi大力 @ 2020-02-07 16:05:40
最后判断那块,e=s输出i如果e>s输出i-1