你代码呢
by SDLTF_凌亭风 @ 2023-11-24 22:53:15
你代码会编译错误的原因是因为:你的数组和变量重名了,都叫a。
by ZWK210917 @ 2023-11-26 16:28:37
改成这样就行了:
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
struct st{
int g,l;
} c[5005];
bool cmp(st x,st y)
{
return x.l < y.l;
}
int main()
{
int n,s,a,b;
cin>>n>>s>>a>>b;
for(int i = 1;i <= n;i++)
{
cin>>c[i].g>>c[i].l;
}
sort(c+1,c+n+1,cmp);
int cur = 1,ab = a+b,ans = 0;
for(;cur <= n;cur++)
{
if(ab >= c[cur].g&&s>=c[cur].l)
{
s -= c[cur].l;
ans++;
}
}
cout<<ans<<endl;
return 0;
}
```
by ZWK210917 @ 2023-11-26 16:31:06