求助dalao!qvqq80分第四个数据WA

P1478 陶陶摘苹果(升级版)

oneofzyl48 @ 2020-01-23 16:49:04

#include<bits/stdc++.h>
using namespace std;

struct apple{
    int height;
    int strength;
};

bool cmp(apple x,apple y)
{
    return x.strength <y.strength ; 
}

int main()
{
    apple tapple[5001];
    int n,i,s,a,b,sum=0,num=0;
    cin>>n>>s;
    cin>>a>>b;
    for(i=0;i<n;i++)
    {
        cin>>tapple[i].height >>tapple[i].strength ;
    }
    sort(tapple,tapple+n,cmp);
    for(i=0;i<n;i++)
    {
        if(tapple[i].height<=a+b)
        {
            sum=sum+tapple[i].strength;
            num++;
            if(sum>s)
            {
                cout<<num-1;
                break;
            }
        }
    }
    return 0;
}

by THoJane @ 2020-01-28 09:13:27

试一下这组数据: 5 0 3 3 1 0 2 0 3 0 4 0 5 0


by _cmh @ 2020-02-04 14:12:20

第四个测试点

输入:

0 0

0 0

输出:

0


|