Editorial for CIW '26 P3 - Gumball Machine
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
The key observation is that the total number of gumballs dispensed equals .
Initially, when
, 0 gumballs are dispenesed.
When we press the button, the total number of gumballs dispensed becomes
.
Similarly, when we press the
buttom, the total number of gumballs dispensed becomes
.
Thus we want to find integers such that
and
is minimized.
Note that the smaller of
and
is at most
, so by iterating through
and checking if they divide
, we can find the pair
which minimizes
.
Time Complexity:
Comments