20分紧急求助

P1478 陶陶摘苹果(升级版)

bohemiao @ 2023-09-22 10:10:57

#include<bits/stdc++.h>
using namespace std;
int a[5005],n,s,b[5005],aa,bb,sum,c[5005];
int main(){
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        c[i]=-1;
    }
    cin>>aa>>bb;
    bb+=aa;
    for(int i=1;i<=n;i++){
        if(a[i]<=bb){
            c[i]=b[i];
        }
    }
    sort(c+1,c+1+n);
    for(int i=1;i<=n;i++){
        if(c[i]!=-1&&s-c[i]>=0){
            s-=c[i];
            sum++;
        }else break;
    }
    cout<<sum;
    return 0;
}

20分只对了#4


by zhangtl527 @ 2023-10-26 19:47:57

可以试着用结构体


|