June long problem ( dynamic programming and bfs)

I am getting wa in this question but i am unable to detect the bug…
question link-https://www.codechef.com/JUNE15/problems/ANCOIMP
solution link- http://ideone.com/ko3FYE

1 Like
//