Plz help solving COOLING Problem??....newbie to codechef

Guys, I have tried solving Cooling problem with many inputs and I even get the desired output on my pc, but still getting “wrong answer” on code chef. Here is my code.

@ http://www.codechef.com/viewsolution/2700993

i’m not into c language, but the potential reason why you might be getting WA, is the special cases which you need to think about separately and then handle. also while testing your code on pc, you might not be testing it for those cases hence getting right answer. So, think again, this time a little deep.
-all the best

Hey change bubble sort to quick sort i have done same in your code and got AC

you can see my submission http://www.codechef.com/viewsolution/2706803

1 Like

in your bubble sort code u r also considering a[n] when i=0 and j=n-1.
so if a[n] is initiated by previous test cases then your code will fail.
i just initiated a[n] to 1000000000 and submitted your code and got accepted.
my submission http://www.codechef.com/viewsolution/2707109.
also a small suggestion try to use std::sort() and std:swap() in your code.

1 Like

didn’t get? how code fails if a[n] initiated by previous test case??..It would be pretty kind of you to explain me out in this regard…newys thanks bro for your useful suggestion :slight_smile:

consider the test case
2
4
1 10 20 30
1 10 20 30
3
10 20 30
10 20 30
->for first test case in bubble sort code a[4] is also considered while sorting but a[4] is not assigned any value so it considers a garbage value for a[4].
after first test case execution wr[]-> “0 0 0 0”.
->for second test case after input wr[] -> “10 20 30 0”
after sorting wr[] -> “0 10 20 30”(since you are also considering a[3] which is assigned value 0 instead of getting “10 20 30 0” your wr[] will be “0 10 20 30”.
so the ans will be printed as 2 instead of 3.
hope this helps :slight_smile:

1 Like

thnkx bro…got it…:slight_smile:

NOTE: in my opinion, it would be nice if you count++ inversely. assume weight is X, and limit is Y func respectively. we have(or reach) our desired count++ when Y’s element is bigger than or equal to X’s particular element. and in that condition we count++. otherwise, we just pass onto Y’s next element, till we meet the condition.