When i ran my program on ide, i got output exactly same as the sample output
But my answer is taken wrong… WHY???

I faced the same thing for greedy dog

Yaa… it happened with me for greedy dog also

It is most likely because you guys are not testing with all possible test cases in the ide.