×

# 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<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 );
}


163811
accept rate: 0%

 3 dude initialise ans and x to zero for every new test case .... you have done that on top only answered 08 Feb '13, 19:52 1.4k●9●22●41 accept rate: 14% 1 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.. (08 Feb '13, 19:55) a very detailed and informative answer for one of the most silliest mistake I committed once again.thanx a lot for helping me :) (08 Feb '13, 22:14) 1 my pleasure :) (09 Feb '13, 13:46)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×3,707
×1,901
×1,056
×29

question asked: 08 Feb '13, 19:02

question was seen: 860 times

last updated: 09 Feb '13, 13:46