求大佬帮忙看看80分,第五个测试点运行时错误(RE)

P1478 陶陶摘苹果(升级版)

Ousmane_Dembele @ 2017-08-19 09:03:36

没看出啥错啊

#include <bits/stdc++.h>
using namespace std;
int n,s,a,b,h,c,d;
int liqi[1001];
int main()
{
    cin>>n>>s;
    if(n==0||s==0){
        cout<<"0";
        return 0;
    }
    cin>>a>>b;
    int i;
    h=a+b;
    if(b==0){
        cout<<"0";
        return 0;
    }
    int q=1;
    for(i=1;i<=n;i++){
        cin>>c>>d;
        if(c<=h){
            liqi[q]=d;
            q++;
        }
    }
    sort(liqi+1,liqi+q+1);
    q=1;
    int sum=0;
    while(s>0){
        s-=liqi[q];
        q++;
        if(s>=0)
            sum++;
        if(q>n)
           break;
    }
    if(sum>0)
       sum--;
    cout<<sum;
    return 0;
}

by Ousmane_Dembele @ 2017-08-19 09:05:07

或者哪位大佬说一下测试点的数据?下载超过限制


by Ousmane_Dembele @ 2017-08-19 09:08:24

已解决,数组开小了。加两0就可以了(为什么啊)


by weiya_WYF @ 2017-08-19 22:47:13

要看数据范围呐,数据范围是5000.所以差不多开5010就够了


by 神奇的刺客 @ 2017-08-23 10:07:03

#include<iostream>
#include<algorithm>
using namespace std;
struct node{
  int x;
  int y;
};
int cmp(node aa,node bb)
{
    return aa.y<bb.y;
}
node app[5001];
int n,s;
int a,b;
int tot;
int main()
{
    int i;
    cin>>n>>s;
    cin>>a>>b;
    for(i=0; i<n; i++)
     cin>>app[i].x>>app[i].y;
   sort(app,app+n,cmp);
    tot = 0;
    for(i=0; i<n; i++)
    {
        if(s-app[i].y<0) 
         break;
        if(a+b>=app[i].x)
         {               
             tot++;
             s = s - app[i].y;
         }
    }
   cout<<tot<<endl;
    return 0;
}

|