用的快排为什么还会TLE,第3和5个点,好奇怪。。。

P1478 陶陶摘苹果(升级版)

lordhu @ 2018-07-19 12:54:54

include<stdio.h>

struct fruit{ int height; int power; };

struct fruit a[6500];

void qsort(int l,int r);

main() { int n,s,i,add,b,c,ans;

scanf("%d%d",&n,&s);
scanf("%d%d",&b,&c);
for(i=1;i<=n;++i) scanf("%d%d",&a[i].height,&a[i].power);

qsort(1,n);
add=ans=0;
for(i=1;i<=n;++i){
    if(a[i].height<=b+c){
        add=add+a[i].power;
        ++ans;
    }
    if(add>s) break;
}
if(ans!=0)printf("%d\n",ans-1);
else printf("0\n");
return 0;

}

void qsort(int l,int r){ struct fruit mid,t; int i,j;

i=l;j=r;mid=a[(l+r)/2];
while(i<=j){
    while(a[i].power<mid.power) ++i;
    while(a[j].power>mid.power) --j;
    if(i<=j){
        t=a[i];
        a[i]=a[j];
        a[j]=t;
        ++i;--j;
    }
if(l<j) qsort(l,j);
if(i<r) qsort(i,r);
} 

}


by 旧巷听风丶 @ 2018-08-01 21:44:25

数组开小了


|