帮帮我 !

P1478 陶陶摘苹果(升级版)

james003 @ 2024-04-13 16:37:34

https://www.luogu.com.cn/record/155669289


by __0__ @ 2024-04-13 16:51:32

这样看不了你的源代码,你的源代码别人看不了的。您应该放上来源代码。


by NaCl_0_9H2O @ 2024-04-13 16:52:31

要用结构体排序

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,s,a,b,o,ans;
struct r{
    int x,y;
}l[5001],l1[5001];
bool cmp(r a,r b){
    return a.y<b.y;
}
int main(){
    cin>>n>>s>>a>>b;
    if(n==0){
        cout<<0;
        return 0;
    }
    a+=b;
    for(int i=0;i<n;i++){
        cin>>l[i].x>>l[i].y;
        if(l[i].x<=a)l1[o++]=l[i];
    }
    sort(l1,l1+o,cmp);
    for(int i=0;i<=o;i++){
        if(l1[i].y>s)break;
        ans++,s-=l1[i].y;
    }
    cout<<ans;
    return 0;
}

|