```cpp
if(s>apple[i].y)
```
应改成
```cpp
if(s>=apple[i].y)
```
by BGM114514 @ 2023-10-31 21:26:03
不知为什么,把sort换成stable_sort就过了
by BGM114514 @ 2023-10-31 21:30:30
AC代码:
```cpp
#include <bits/stdc++.h>
using namespace std;
struct app{
int x,y;
app():x(0),y(0){}
};
bool cmp(app a,app b){
return a.y<=b.y;
}
int s,n,b,a,num;
app apple[5005];
int main(){
cin>>n>>s;
cin>>a>>b;
for(int i=1;i<=n;i++){
cin>>apple[i].x>>apple[i].y;
}
stable_sort(apple+1,apple+n+1,cmp);
for(int i=1;i<=n;i++){
if(s>=apple[i].y){
if(apple[i].x<=a+b){
num++;
s-=apple[i].y;
}
}
}
cout<<num<<endl;
return 0;
}
```
by BGM114514 @ 2023-10-31 21:31:39
@[BGM114514](/user/705058) AC了,谢谢大佬
by andy605 @ 2023-11-05 09:26:42
@[BGM114514](/user/705058) 已关,谢谢
by andy605 @ 2023-11-05 09:27:14