大佬帮忙看一下,为什么输出的不对?

P1478 陶陶摘苹果(升级版)

aizehao123 @ 2022-06-29 21:46:34


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

by XYini @ 2022-06-29 21:59:44

应该是

s-=k[i].y

by aizehao123 @ 2022-06-30 15:55:35

@LxYiiiiii 谢谢大佬


|