求助

P1478 陶陶摘苹果(升级版)

Lemon_tea @ 2019-08-30 11:26:24

为什么错了

#include<bits/stdc++.h>
using namespace std;
struct apple{
    int xi,yi;
};
int a,b,n,s,sum=0;
apple ap[6000];
bool comp(apple a,apple b){
    return a.yi<b.yi;
}
int main(){
    cin>>n>>s;
    cin>>a>>b;
    for(int i=1;i<=n-1;i++){
        cin>>ap[i].xi>>ap[i].yi;
    }
    sort(ap+1,ap+n,comp);
    for(int i=1;i<=n;i++){
        if(ap[i].yi<=s&&ap[i].xi<=a+b){
            sum++;
            s=s-ap[i].yi;
        }
    }
    cout<<sum;
    return 0;
}

by zrz_orz @ 2019-08-30 11:31:35

  for(int i=1;i<=n-1;i++){
        cin>>ap[i].xi>>ap[i].yi;
    }

为什么是n - 1


by royzhu @ 2019-08-30 11:33:24

 for(int i=1;i<=n-1;i++){
        cin>>ap[i].xi>>ap[i].yi;
    }

n-1哪来的

@柠檬茶


by Lemon_tea @ 2019-08-30 12:53:53

谢谢


|