求助!只有40分!

P1478 陶陶摘苹果(升级版)

HbugU @ 2021-05-26 21:01:59

#include<bits/stdc++.h>
using namespace std;
int n,s,a,b,h,ans=0,p[5005],q[5005];
struct node{
    int x,y;
}apple[5005];
bool cmp(node e,node f){
    return e.y<f.y;
}
int main(){
    cin>>n>>s>>a>>b;
    h=a+b;
    int j=0;
    for(int i=0;i<n;i++){
        cin>>p[i]>>q[i];
        if(p[i]<=h){
            apple[j].x=p[i];
            apple[j].y=q[i];
            j++;
        }
    }
    sort(apple,apple+j-1,cmp);
    j=0;
    int t=0;
    while(s>=apple[t].y){
        ans+=1;
        s-=apple[t].y;
        t++;
    }
    cout<<ans;
    return 0;
}

by _l_l_l_l_l_ @ 2021-05-26 21:24:33

你好像没判断能不能够到


|