WA in COOLING

Following is the code I used for the problem Cooling Pies(http://www.codechef.com/problems/COOLING)> Itried many test cases but when I run the judge it says wrong answer please help.

#include
#include<stdlib.h>
int compare (const void * a, const void * b);
int main()
{
int a[30]={0},b[30]={0},cases,num,ans=0,x=0;
scanf("%d",&cases);
for(int i=0;i<cases;i++)
{
scanf("%d",&num);
for(int j=0;j<num;j++)
{
scanf("%d",&a[j]);
}
for(int k=0;k<num;k++)
{
scanf("%d",&b[k]);
}
qsort(a,30,sizeof(int),compare);
qsort(b,30,sizeof(int),compare);
for(int l=0;l<num;l++)
{
if(b[x]>=a[l])
{
ans+=1;
x+=1;
}
}
printf("%d\n",ans);
}
}
int compare (const void * a, const void * b)
{
return ( (int)b - (int)a );
}

dude initialise ans and x to zero for every new test case … you have done that on top only

3 Likes

your statement ans=0 and x=0 will be inside for loop.

further more use #include for scanf n printf

also #include is correct header…

plus qsort((void*)a,30,sizeof(int),compare); typecast it to be on safer side :)… hope that will help…

1 Like

a very detailed and informative answer for one of the most silliest mistake I committed once again.thanx a lot for helping me :slight_smile:

my pleasure :slight_smile:

1 Like
//