I cant understand the the solution on this link. can anyone explain??

If I am guessing correctly, then like me you would have found difficult to understand this statement from the question “…and all of them wants his amount of pizza in one slice.” This means that each person wants his slice of pizza to be whole, ie it must not be the sum of smaller slices. If a person wants 3/4 pizza and you have 3 extra slices of 1/4 pizza you cannot give it to him.

Now, I am rewriting a part of the accepted solution for better understandability:

sum += count3 + ceil(count1/2);

extra = count3 + (count1%2)*2; //could be written as extra = count3 + (count1%2)==1?2:0;

if (count2 >= extra)

{

count2 -= extra;

sum += ceil(count2 / 4);

}

The first line makes sum equal to number of 3/4 plus ceiling of (count1/2). For each 3/4 pizza we have one 1/4 pizza extra. If count1 is odd we have two 1/4 pizza extra. ‘extra’ is the sum of these two. The rest of the code is straightforward.