In the if(g!=-1)
statement you have g
remaining groups of 1 person. They have to take (g+3)/4
taxis, and not g
.
In other words change this line f=f+g;
to f=f+(g+3)/4;
.
Btw, you can use the operator +=
for such operations. For example, e=e+1
will become e += 1
or even better e++;
(when you increase the number with exactly one).