求助,这题为什么只得了40分,2AC,2WA,1RE

P1478 陶陶摘苹果(升级版)

帅帅的轩轩 @ 2019-11-08 16:46:16

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
long long n,v,a,b,s[1000],x[1000],ans;
int main()
{
    cin>>n>>v;
    cin>>a>>b;
    for(int i=1;i<=n;i++)cin>>s[i]>>x[i];
    for(int i=1;i<=n-1;i++)
    {

        if(b+a>s[i])v-=x[i],ans++;
        if(n+a<s[i])continue;
        if(v-x[i]<0){ans--;break;}
        if(v-x[i]==0)break;
    }
    cout<<ans;
    return 0;
}

by watermonster @ 2019-11-08 17:10:42

按读入顺序选取苹果会导致WA\ 应该先按花费从小到大排序\ 至于RE你数组开小了..\ 所有数据:n<=5000


|