20分,求大佬改错,真是不知道自己错在哪里,萌新

P1478 陶陶摘苹果(升级版)

快乐的ZSQ @ 2019-09-20 22:57:27

include<iostream>

include<cstdio>

using namespace std;

int main(){

int b,n,s,a,x,count=0;
cin>>n>>s>>a>>b;
b=b+a;
for(int i=1;i<=n;++i){
    int x,y;
    cin>>x>>y;
    if(x <= b && (s-y) >= 0){
        count++;
        s-=y;
    }
    if(s<=0){
        break;
    }
}
cout<<count;

}


by    吾皇 @ 2019-09-20 23:05:58

@zhangshuaiqi ..贪心算法求解


by 快乐的ZSQ @ 2019-10-04 21:28:44

@   吾皇 大神我还没学过,但是我觉得我这个可以解出来,求指出错误


by    吾皇 @ 2019-10-05 12:41:44

@zhangshuaiqi 显然要先摘花费力气小的苹果


by 快乐的ZSQ @ 2019-10-06 11:30:03

@   吾皇 谢谢大佬,我过了


|