BEX-Runtime error

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


or
http://www.codechef.com/viewsolution/1630661

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

5
20 a
0 b
10 c
-1
-1
2 Likes

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

11
9 english
2 mathematics
8 geography
5 maths
7 zoology
-1
3 graphics
-1
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.

2 Likes

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 .

3 Likes

@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 !

ohh!!!..thanks…:slight_smile:

@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

thanks…:slight_smile:

@anuraganand again wrong answer…http://ideone.com/un6AUH

I was trying out this problem:

I dont understand why I am getting Runtime error.
I had the same approach as in the editorial.
http://www.codechef.com/viewsolution/1855440

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

Thanks