BEX-Runtime error

whats the reason for runtime error in my code??..its running correctly on ideone…pls help out…
here is the link:


Did you test your code? I tried first case and it failed…

20 a
0 b
10 c

Try this case also , it fails here also ,
I checked on Ideone also

9 english
2 mathematics
8 geography
5 maths
7 zoology
3 graphics
8 maths
7 english
9 botany

Gives runtime error

You are not updating ‘k’ in your code which is to track the total number of books currently in the stack , i guess .
There may be other mistakes in your code , but this one is definitely there.


Also there is one obvious logical error .

After the removal of some number of book above and including the minimum , the new minimum will be in books left apart from the books that may get added further . You can’t just update new minimum on the basis of current minimum and the number just added .

Say you have
3 maths
5 science
2 english
8 zoology

after english is removed , if i add “9 botany” and then remove by giving “-1” then you should pop out maths .


@vineetpaliwal…thanks i got the mistake in my code …:slight_smile:

thanks a lot for ur suggestions but now according to me, i have made the correct code with all the changes and its giving correct answer on my sets of input…but on codechef again wrong answer…pls help out…

@betlista …thanks…but nw i m getting wrong answer…pls check out…

you dont have to add books with zero exercises to pile !


@anuraganand…but now also it is givin wrong answer…check out:

What if top =0 ?
You are still using prev min value
Add this statement
if(top==0) min=lim;

1 Like


@anuraganand again wrong answer…

I was trying out this problem:

I dont understand why I am getting Runtime error.
I had the same approach as in the editorial.

Please can anyone provide me some testcase which is causing SIGSEV??