← March 2025 questions

MARCH 2025 / ADVANCED / QUESTION 3

Question 3

Archived question

Try the question in your own editor, then check your output below.

THE QUESTION

Text from the official booklet. Refer to the PDF for original mathematical notation, formatting, and linked input files. Printed samples and inputs are reproduced as published.

A scientist is experimenting with liquid mixtures using three containers of different capacities.
Each container initially holds a certain amount of liquid, but they are not necessarily full. The
scientist performs a sequence of transfers in a cyclic manner:
Pouring from container 1 into container 2
Pouring from container 2 into container 3
Pouring from container 3 into container 1
This process repeats for a total of 100 pours (so the 100th pour would be from container 1 into
container 2). Each time, the scientist transfers as much liquid as possible from one container to
the next, stopping when either the source container is empty or the destination container is full.
Your task is to determine how much liquid remains in each container after all 100 pours.
The first line of the input file contains two space-separated integers: the capacity c1 of the first
bucket, and the amount of milk m1 in the first bucket. Both c1 and m1 are positive and at most 1
billion, with c1 ≥ m1. The second and third lines are similar, containing capacities and milk
amounts for the second and third buckets.
Please print three lines of output, giving the final amount of milk in each bucket, after 100 pour
operations.
SAMPLE INPUT:
10 3
11 4
12 5
SAMPLE OUTPUT:
0
10
2
Input
Case 1:
695789 393585
705404 502652
999933 95061
Case 2:
855636227 749698587
687926653 660260757
959997302 485560281

CHECK YOUR ANSWER

Try your answer.

Run your program in your own editor, then paste its output below. This checks the stated output; it does not assess your full program. Practice attempts do not affect competition scores.

Use the corresponding input from the question. For lists, brackets and commas are optional for numeric answers; text lists may also be entered one item per line.

Use the corresponding input from the question. For lists, brackets and commas are optional for numeric answers; text lists may also be entered one item per line.

Reveal worked answer

Case 1

0
695789
295509

Case 2

381199206
687926653
826393766

Simulate all 100 pours cyclically, transferring min(source amount, destination free capacity) each time.

Reveal supplied answers

From the supplied Advanced answer key. Outputs are reproduced as provided.

Case 1

0
695789
295509

Case 2

381199206
687926653
826393766

Source: GIC 2025 Advanced Questions and the supplied Advanced answer key, March 2025 archive.