wa c [BEX]

hey… plz look at this solution,it’s generating WA each time: http://www.codechef.com/viewsolution/2402560
problem: http://www.codechef.com/problems/BEX
plz help, am pissed off this problem.

Check this case.

6
9 english
-1
3 graphics
-1
6 mathematics
-1

You code should be throwing a SIGSEGV for this test case. (But it is not, and I don’t know why!)

The idea is this. First, you add a book. Then, you take it out. After this point, in your code, value of i is -1. Now, you add another book on to the pile. In your code, the check if(l<=b[i].serial) will execute. But b[-1] is undefined. This should have thrown a SIGSEGV.

Try making sufficient changes to handle the case, when you are adding a book on top of an empty pile. This might be the reason.

Programming Tip: Try indenting your code. It is easy to understand/debug. :slight_smile:

2 Likes