Walk Alone is thirsty and he wants to drink water. He wants to drink exactly
x units of water, but he does not have an appropriate measuring cup. He only has two water bottles of volume
A and
B respectively. He found out that he could do the following operations with the two bottles:
-
Fill one of the two bottles with water.
-
Spill all water from one of the two bottles.
-
Drink all water from one of the two bottles.
-
Transfer as much water as possible from one bottle to the other with no water overflow. Formally speaking, if the two bottles contain a and b units of water respectively, he can only transfer min(a,B−b) water from A to B or min(b,A−a) from B to A.
Walk Alone wants to do as few operations as possible. Can you tell him the minimum number of operations he should do to drink exactly
x units of water?