Balife problem (greedy algorithms)

i am unable to do this problem.
pls tell the code.

@yutikakhanna here is the code for this question (https://ide.codingblocks.com/s/201282).