COOLING - Wrong Answer

cooling
practice

#1

Can someone please tell me where i am going wrong? I am getting WA.
Following is the link to my code :

http://ideone.com/kDW4FE

Thanks a lot.


#2

You need to sort the array of pies and racks first. The rest of your logic was almost correct.

Here is the corrected code - http://www.codechef.com/viewsolution/3927466


#3

@wittyceaser I used bubble sort to sort the arrays as the input size is limited to 30.


#4

That’s okay.


#5

You said that i need to sort the arrays which i did sort ,then why was it giving a wrong answer?

Thanks a lot for your help.


#6

In the latter part of your code, you have written:

if(w*>m[j])
i++;

Basically, if the weight of a pie - i , is greater than the capacity of a rack - j (i.e., w* > m[j]), then that rack is not useful for us, so we’ll try the next rack. Hence, j++ and not i++.


#7

thanks a lot!