求调qwq

P1478 陶陶摘苹果(升级版)

Sunnnnnn @ 2024-06-28 16:20:53

#include <bits/stdc++.h>
using namespace std;
struct node{
    int x,y;
}tr[5005];
bool cmp(node a,node b){
    return a.y<b.y;
}
int main() {
    int n,s,a,b,cnt=0;
    cin>>n>>s>>a>>b;
    for(int i=1;i<=n;i++){
        cin>>tr[i].x>>tr[i].y;
    }
    sort(tr+1,tr+n+1,cmp);
    for(int i=1;i<=n&&s>=0;i++){
        if(a+b>=tr[i].x){
            cnt++;
            s-=tr[i].y;
        }
    }
    cout<<cnt;
    return 0;
}

by lzm0107 @ 2024-06-28 16:27:40

@Sunnnnnn

#include <bits/stdc++.h>
using namespace std;
struct node{
    int x,y;
}tr[5005];
bool cmp(node a,node b){
    return a.y<b.y;
}
int main() {
    int n,s,a,b,cnt=0;
    cin>>n>>s>>a>>b;
    for(int i=1;i<=n;i++){
        cin>>tr[i].x>>tr[i].y;
    }
    sort(tr+1,tr+n+1,cmp);
    for(int i=1;i<=n&&s>=0;i++){
        if(a+b>=tr[i].x&&s>=tr[i].y){
            cnt++;
            s-=tr[i].y;
        }
    }
    cout<<cnt;
    return 0;
}

by Sunnnnnn @ 2024-06-28 18:02:45

@lzm0107 谢谢!


|