#P5116. Milk Mixing Simulation
Milk Mixing Simulation
Milk Mixing Simulation
In the agricultural industry, particularly in dairy production, competition is fierce. Farmer John has discovered that without innovation, his dairy business could suffer. Fortunately, he comes up with a clever idea: by mixing the milk from his three prize‐winning cows—Bessie, Elsie, and Mildred—he hopes to create the perfect flavor blend.
He has three buckets, each initially holding the milk from one of his cows. Note that the buckets may have different capacities and may not be full. Farmer John carries out a sequence of pouring operations exactly 100 times. The operations follow a cyclic order: pour from bucket 1 to bucket 2, then from bucket 2 to bucket 3, then from bucket 3 to bucket 1, and repeat. In the ith operation the pouring is done from bucket a to bucket b where the operation order is defined as follows:
[ \text{if } i \equiv 1 ; (\bmod\ 3): \text{pour from bucket 1 to bucket 2},\ \text{if } i \equiv 2 ; (\bmod\ 3): \text{pour from bucket 2 to bucket 3},\ \text{if } i \equiv 0 ; (\bmod\ 3): \text{pour from bucket 3 to bucket 1}. ]
When pouring from bucket (a) to bucket (b), Farmer John pours as much milk as possible until either bucket (a) is empty or bucket (b) is full. Your task is to determine the final amount of milk in each bucket after 100 pouring operations.
inputFormat
The input consists of three lines. Each line contains two integers separated by a space: the capacity of the bucket and the current amount of milk in that bucket. The buckets are numbered 1, 2, and 3 respectively.
outputFormat
Output three lines. The first line should contain the final amount of milk in bucket 1, the second line the final amount for bucket 2, and the third line the final amount for bucket 3 after 100 pouring operations.
sample
10 3
11 4
12 5
0
10
2
</p>