spoj KGSS WA

I am getting a WA on the ques KGSS on spoj. ( http://www.spoj.com/problems/KGSS/ )
my solution is
http://ideone.com/7dvrao

thanx :slight_smile:

//