Cooling PiesProblem code: COOLING |
All submissions for this problem are available.
The chef has just finished baking several pies, and it's time to place them on cooling racks. The chef has exactly as many cooling racks as pies. Each cooling rack can only hold one pie, and each pie may only be held by one cooling rack, but the chef isn't confident that the cooling racks can support the weight of the pies. The chef knows the weight of each pie, and has assigned each cooling rack a maximum weight limit. What is the maximum number of pies the chef can cool on the racks?
Input:
Input begins with an integer T?30, the number of test cases. Each test case consists of 3 lines. The first line of each test case contains a positive integer N?30, the number of pies (and also the number of racks). The second and third lines each contain exactly positive N integers not exceeding 100. The integers on the second line are the weights of the pies, and the integers on the third line are the weight limits of the cooling racks.
Output:
For each test case, output on a line the maximum number of pies the chef can place on the racks.
Sample input:
2 3 10 30 20 30 10 20 5 9 7 16 4 8 8 3 14 10 10
Sample output:
3 4
| Author: | pieguy |
| Date Added: | 27-09-2010 |
| Time Limit: | 1 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

Can some one explain me why
Can some one explain me why this is a wrong answer???
#include<stdio.h>
#include<stdlib.h>
typedef struct _case
{
int pies;
int * pieweights;
int *panweights;
}cases;
int main()
{
int i=0,j=0,k=0,l=0,t=0,sum=0;
int tcases=0,index=0;
int *temp = NULL;
cases *allcases;
// printf("Enter no of test casesn");
scanf("%d",&tcases);
allcases = (cases *)malloc(tcases*sizeof(cases));
for(i=0;i<tcases;i++)
{
sum=0;
printf("Enter the case details----no of piesn");
scanf("%d",&(allcases[i].pies));
allcases[i].pieweights = (int *)malloc((allcases[i].pies)*sizeof(int));
allcases[i].panweights = (int *)malloc((allcases[i].pies)*sizeof(int));
temp=(int *)realloc(temp, allcases[i].pies*sizeof(int));
// printf("nEnter pie weights");
for(j=0;j<allcases[i].pies;j++)
{
scanf("%d",&(allcases[i].pieweights[j]));
temp[j]=-1;
}
// printf("n Enter pan weights");
for(j=0;j<allcases[i].pies;j++)
scanf("%d",&(allcases[i].panweights[j]));
for(k=0;k<allcases[i].pies;k++)
{
t=0;
for(l=0;l<allcases[i].pies;l++)
{
if(allcases[i].pieweights[k]<=allcases[i].panweights[l])
{
if((t<(allcases[i].panweights[l]))&&temp[l]!=0)
{
t=allcases[i].panweights[l];
index=l;
}
}
}
temp[index]=0;
}
for(l=0;l<allcases[i].pies;l++)
{
if(temp[l]==0)
sum++;
}
// printf("No of possible placings for this case is %d",sum);
}
return 0;
}
@admin plz..........tell me
@admin
plz..........tell me for which test case my code generate wrongh output????
thanks in advance...........
#include<stdio.h>
int pie[100],rack[100];
void bubble_sort(int a[], int size)
{
int switched = 1;
int hold = 0;
int i = 0;
int j = 0;
size -= 1;
for(i = 0; i < size && switched; i++)
{
switched = 0;
for(j = 0; j < size - i; j++)
{
if(a[j] > a[j+1])
{
switched = 1;
hold = a[j];
a[j] = a[j + 1];
a[j + 1] = hold;
}
}
}
}
int solve(int max)
{
int c=0,j,k;
j=max-1;
k=max-1;
while(j>=0&&k>=0)
{
if(pie[j]<=rack[k])
{
j--;
k--;
c++;
}
else
j--;
}
return c;
}
int main()
{
int ans,i,t,m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&pie[i]);
for(i=0;i<m;i++)
scanf("%d",&rack[i]);
bubble_sort(pie,m);
bubble_sort(rack,m);
ans=solve(m);
printf("%d",ans);
}
return 0;
}
Please do NOT post your code
Please do NOT post your code here. Read FAQ. You can post the link to your code. :)
plzzzzzz help !!!!!!!! whats
#include void main() { int
Can someone explain why this
@Admin: When I submit, the
My code is working fine on my
Plz somebody help : My code
please anyone post such more
please anyone post such more
OK My code works with the
@shubhammnnit - Try altering
need more test cases...