CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Cooling Pies

Cooling Pies

Problem code: COOLING

  • Submit
  • All Submissions

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


  • Submit

Comments

  • Login or Register to post a comment.

Can some one explain me why

vinaymajety @ 14 Dec 2010 08:35 PM

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

satya_patel @ 31 Jan 2011 04:34 PM

@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

rajneesh2k10 @ 31 Jan 2011 04:48 PM

Please do NOT post your code here. Read FAQ. You can post the link to your code. :)

plzzzzzz help !!!!!!!! whats

k.sampath kumar @ 30 May 2011 09:35 PM
plzzzzzz help !!!!!!!! whats wrong with my code.it is giving correct answer for given inputs. #include int i,b[30],j,k=0,count=0; void merge_sort(int *,int,int); void sort(int *,int,int,int); void main() { int T,N,*a1,*b1; int left,right,mid; scanf("%d",&T); while(T) { scanf("%d",&N); a1=(int *)malloc(N*sizeof(int)); b1=(int *)malloc(N*sizeof(int)); for(i=0;imid) { for(k=j;k<=right;k++) { b[i]=a[k]; i++; } } else { for(k=l;k<=mid;k++) { b[i]=a[k]; i++; } } for(k=left;k<=right;k++) { a[k]=b[k]; } }

#include void main() { int

pprateek @ 19 Jun 2011 01:34 PM
#include void main() { int t,n,i,x,y,a[100],b[100],flag,temp,j,count; scanf("%d",&t); while(t--) { x=0;y=0; scanf("%d",&n); for(i=0;i=a[i]) count=count+1; } if(count>=i+1-x) y=y+1; else if(count==0&&y==0) x=x+1; } printf("%dn",y); } } SIR, PLEASE TELL FOR WHICH INPUTS MY CODE WENT WRONG...

Can someone explain why this

munishgoyal @ 23 Jun 2011 03:25 PM
Can someone explain why this is wrong http://www.codechef.com/viewsolution/582106 Sort both pies and racks arrays. then advance pies index only if it matches (count++ here) with current rack. rack index is always advanced. this is straightfwd and my local testing seems fine, still got wrong solution.

@Admin: When I submit, the

ambeco @ 1 Oct 2011 04:39 AM
@Admin: When I submit, the "Successful Submission" says "Running" for many minutes. When I click "My Submissions" it says "No recent Activity." It has been at least five minutes.

My code is working fine on my

mygaurav @ 31 Oct 2011 10:37 AM
My code is working fine on my system but here it shows "time limit exceeded". Plz tell what error am i commiting ....http://www.codechef.com/viewsolution/717996

Plz somebody help : My code

mygaurav @ 13 Nov 2011 01:28 PM
Plz somebody help : My code is working fine on my system but here it shows "time limit exceeded". Plz tell what error am i commiting ... http://www.codechef.com/viewsolution/717996

please anyone post such more

shubhammnnit @ 15 Jan 2012 12:49 AM
please anyone post such more test cases so that i can identify that in which case my code produce wrong answer..i am still not able too find error in my code..

please anyone post such more

shubhammnnit @ 15 Jan 2012 12:50 AM
please anyone post such more test cases so that i can identify that in which case my code produce wrong answer..i am still not able too find error in my code..

OK My code works with the

crystalshardz @ 11 Apr 2012 09:12 PM
OK My code works with the test cases provided. I've also tried cases where I have a value of 0 for the weight limit and/or the pie's weight AND checked negative values. Everything works fine on my system (even rote out what the answers should be on pen and paper to check against) but on here it says its wrong...anyone help please? http://www.codechef.com/viewsolution/977117

@shubhammnnit - Try altering

crystalshardz @ 12 Apr 2012 01:24 PM
@shubhammnnit - Try altering the way you filter your pies. Also, use for loops as they seem to be quicker than while loops. Try to nest 2 loops into 1 for processing the pies (would need 3 if you include the loop to process the incoming input)

need more test cases...

abhinav1592 @ 22 May 2012 01:34 AM
need more test cases...

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

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.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com