#P7366. Moon Tree Synchronization
Moon Tree Synchronization
Moon Tree Synchronization
A legendary moon tree grows in a very unusual way. A seed is found that, when planted, becomes a small tree of height \(1\) (one unit) on the next morning. Each morning every tree grows naturally by \(1\) unit. In addition, every day the gardener receives a unit of a special fertilizer. Every evening, the gardener must use exactly one unit of this fertilizer on exactly one target, where the target can be either an already‐planted tree or a seed planted in that afternoon. The fertilized target will gain an extra growth of \(1\) unit the following morning (i.e. it grows by \(2\) units instead of \(1\)).
The moon tree has two special harvesting points during its growth, at heights \(\mathrm{HP1}\) and \(\mathrm{HP2}\). When a tree's height reaches or exceeds one of these thresholds for the first time (checked at noon), the tree bears a fruit. Each fruit contains a seed that is identical to the original one. Every afternoon, the gardener may choose to plant any number of available seeds (including none).
The ultimate goal is to have exactly \(M\) trees whose heights are all equal. Only when exactly \(M\) trees have the same height will they be truly adapted and live forever on Earth. Given the peculiar daily routine and growth rules of the moon tree, your task is to determine the minimum number of days required to achieve exactly \(M\) synchronized trees, assuming the gardener adopts an optimal strategy.
Note: The process begins on day 0 in the afternoon when the initial seed is planted. The following day’s morning, that seed becomes a tree; its height will be affected by whether it was fertilized in the previous evening, and so on.
Remark on the optimal strategy: After careful analysis it turns out that if \(M = 1\) then the answer is \(1\) (since the initial tree qualifies). Otherwise, under an optimal schedule, the minimum required days is given by the formula:
[ \text{Days} = \mathrm{HP1} + \mathrm{HP2} + M - 3. ]
You are to implement a program that reads the three integers \(M\), \(\mathrm{HP1}\) and \(\mathrm{HP2}\) from input and outputs the minimum number of days required.
inputFormat
The input consists of a single line containing three space‐separated integers: \(M\), \(\mathrm{HP1}\), and \(\mathrm{HP2}\).
\(1 \le M, \mathrm{HP1}, \mathrm{HP2} \le 10^3\)
outputFormat
Output a single integer — the minimum number of days required to have exactly \(M\) trees that are all of equal height.
sample
1 2 3
1