SPOJ ARGCOWS doubt

I think the logic is right, however am not getting the right answers, it would be great if someone could point out any mistake.

SPOJ ques: https://www.spoj.com/problems/AGGRCOW/
Code: https://ide.codingblocks.com/#/s/19959