UVa 11689

Tim has e + f empty soda bottles. With c empty bottles, he can get a new soda. How many sodas can he drink?

Explanation
Since e, f and c are small (e < 1000, f < 1000, 1 < c < 2000), a simulation can be done, i.e. while the current empty bottles are larger or equal to c, we use c bottles to get a new one, drink it, and include this one as an empty bottle.

Alternatively, we might realize that each time that Tim drinks a bottle, the number of empty bottles is reduced by c - 1. Thus, it might appear that (e + f) / (c - 1) solves the problem. However, this has the issue that when there are only c-1 bottles, it uses them to get a new one, which is not correct. Thus, the correct formula is max{e + f - 1, 0}/(c - 1).

Gotchas

 * Be careful with the case where we have initially 0 bottles.

Input
8 371 832 39 623 487 366 150 616 793 768 848 779 90 222 1882 265 94 1553 815 438 997 0 0 2

Output
31 3 0 2 0 0 1 0