第4个点RE了,大佬帮看看

P1478 陶陶摘苹果(升级版)

一个黄应该不难,我看看
by Weizhuo_Zhao @ 2023-07-02 16:44:38


@[xinglili](/user/981994) 万一淘淘全摘完了呢。。。 ```cpp #include<iostream> #include<algorithm> using namespace std; const int N=6e3; int n,s; int a,b; int f[N];//每个水果消耗的力气 int main() { cin>>n>>s; cin>>a>>b; int cnt=0; for(int i=0;i<n;i++) { int x,y; cin>>x>>y; if(x<=a+b)f[cnt++]=y; } sort(f,f+cnt); int ans=0; while(s>=0&&ans<=cnt) { s-=f[ans++]; } cout<<ans-1; return 0; } ```
by A1438329629 @ 2023-07-02 16:49:21


@[A1438329629](/user/583276) 懂了,谢谢
by xinglili @ 2023-07-02 17:17:54


@[xinglili](/user/981994) 其实第四个点就是4个0 如果按你的代码打的话0-0会一直是0,就结束不了了,所以在前面加一个n=0的特判就可以了。
by gotocspandbetter @ 2023-08-08 16:36:57


|