#1 WA 其他的都过了,求大佬挑错

P1478 陶陶摘苹果(升级版)

littleseven @ 2019-07-27 15:13:17

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=5050;

int n,s,a,b,cnt,ans;
struct APPLE{ int x,y; }apple[maxn];
bool cmp(APPLE a,APPLE b){ return a.y<b.y; }

int main()
{
    cin>>n>>s; cin>>a>>b; int reach=a+b;
    for(int i=1;i<=n;i++)
    {
        int xx,yy; cin>>xx>>yy;
        if(xx<=reach) apple[++cnt].x=xx,apple[cnt].y=yy;
    }
    sort(apple+1,apple+1+cnt,cmp);
    for(int i=1;i<=cnt;i++)
    {
        if(s>apple[i].y) ans++,s-=apple[i].y;
    }
    cout<<ans<<endl;
    return 0;
}

by wuzhaoxin @ 2019-07-27 15:27:33

大于等于

if(s>apple[i].y)

|