这种事情绝对很奇怪的啊

P1478 陶陶摘苹果(升级版)

Zxx20120715 @ 2024-11-23 17:32:30

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

就很蒙,零蛋(紫叶衬红花)求调。


by dhlsgjr @ 2024-11-23 17:52:18

样例也没过你是怎么敢交的(纯个人意见,无恶意)


by dhlsgjr @ 2024-11-23 18:03:24

@Zxx20120715

AC 代码

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

求关


by Zxx20120715 @ 2024-11-23 19:54:57

@dhlsgjr 谢谢啊

打梦熊打多了


|