Comments

include <stdio.h> should do the trick

Consider this input:

4
2 0 0
1 0 2
0 0 0
0 0 0

Your answer is 1 2 4 and it should be 1 2. First kid scare off third one and there are two remaining, one goes in and scare the other. Your solution tries to compute everything in one go, but every time you need to compute decreasing scream first and then do the runnning. Hence O(n^2) complexity. Hope this helps.