3,5RE了,求调

P1478 陶陶摘苹果(升级版)

lzx0 @ 2023-05-11 20:06:55

RT

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

by LiJoQiao @ 2023-05-11 20:13:36

数组开小了


by jimeikun_sunxuhao @ 2023-05-11 20:18:49

您数组越界了


by lzx0 @ 2023-05-11 20:23:24

@LiJoQiao 然后就wa了....


by lzx0 @ 2023-05-11 20:23:53

@jimeikun_sunxuhao 然后就wa了...


by jimeikun_sunxuhao @ 2023-05-11 20:42:24

你为啥要从大到小排序啊


by jimeikun_sunxuhao @ 2023-05-11 20:43:24

应该从小到大,优先摘低的苹果啊


by lzx0 @ 2023-05-12 13:33:43

@jimeikun_sunxuhao 好吧,我眼瞎


|