为啥会RE,求大佬帮助(蒟蒻也行)

P1478 陶陶摘苹果(升级版)

小罐猹 @ 2018-08-27 19:21:53

#include<iostream>
#include<algorithm>
using namespace std;
struct apple
{
    int high;
    int energy;       
};
apple a[5005];
bool cmp(apple x,apple y)
{
    if(x.energy<=y.energy)  return true;
    return false;    
}
int main()
{
    int n,s,i;
    int sum=0;
    cin>>n>>s;
    int c,b;
    cin>>c>>b;
    b+=c;
    for(i=1;i<=n;i++)
      cin>>a[i].high>>a[i].energy;
    sort(a+1,a+n+1,cmp);
    for(i=1;i<=n;i++)
    {
        if(s-a[i].energy<0)  break;
        if(b<a[i].high)  continue;
        sum++;
        s-=a[i].energy;                 
    }
    cout<<sum<<endl;
    return 0;
}

by Anguei @ 2018-08-27 19:46:34

第十行改成: if(x.energy<y.energy) return true; 要不然一旦有重复数字就爆了


by Anguei @ 2018-08-27 19:46:55

@lingxiaoyu


by 小罐猹 @ 2018-08-28 12:57:01

@yyfcpp 谢谢


by 小罐猹 @ 2018-08-28 12:59:49

@yyfcpp 已经过了,谢谢大佬


by Victorss @ 2019-03-31 11:54:28

@Anguei 为什么会爆哇。求解答


|