求调,测试用例跟测试点1输入输出都对但是WA

P1478 陶陶摘苹果(升级版)

Whiskey_ @ 2024-11-23 15:31:44

求调

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,s,a,b,x[5001],y[5001],sum=0;
    cin>>n>>s>>a>>b;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(int i=1;i<=n;i++){
        for(int j=n;j>1;j--){
            if(y[j]<y[j-1]){
                swap(x[j],x[j-1]);
                swap(y[j],y[j-1]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(x[i]<=a+b&&s-y[i]>=0){
            sum++;
            s-=y[i];
        }
    }
    cout<<sum;
    return 0;
}

by zhangbenshi @ 2024-11-27 20:52:08

改对啦

求关


by zhangbenshi @ 2024-11-27 20:52:38

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,s,a,b,x[5001],y[5001],sum=0;
    cin>>n>>s>>a>>b;
    for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(int i=1;i<=n-1;i++){
        for(int j=1;j<=n-i;j++){
            if(y[j]>y[j+1]){
                swap(y[j],y[j+1]);
                swap(x[j],x[j+1]);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(x[i]<=a+b&&s-y[i]>=0){
            sum++;
            s-=y[i];
        }
        else continue;
    }
    cout<<sum;
    return 0;
}

by lj2013 @ 2025-01-02 09:01:17

本来就对!


|