第五个wa求调

P1478 陶陶摘苹果(升级版)

xiao_liran @ 2024-06-26 22:25:00


#include <bits/stdc++.h>
using namespace std;
int n,s;
int a,b;
int x[10000],y[10000];
int main(){
    cin>>n>>s;
    cin>>a>>b;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    int h=b+a;
    for(int i=0;i<n;i++){
        if(x[i]>h){
            x[i]=-100;
        }
    }

    for(int i=0;i<n;i++)
    {
        for (int j=i;j<n;j++)
        {
            if (y[i]>y[j])
            swap(y[i],y[j]);
        }
    }  
    int ans=0;
    for(int i=0;i<n;i++){
        s-=y[i];
        if(x[i]==-100){
            s+=y[i];
            continue;
        }

        else if(s>0) ++ans;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}

by xiao_liran @ 2024-06-26 22:25:26

qiuqiule


|