#P4817. Fruit Feast Problem
Fruit Feast Problem
Fruit Feast Problem
Bessie has broken into Farmer John's house again! She has discovered an unlimited pile of lemons and oranges. Eating an orange increases her fullness by A, and eating a lemon increases her fullness by B. Bessie cannot exceed a fullness of T (i.e. $1 \leq T \leq 5\,000\,000$ and $1 \leq A,B \leq T$). Additionally, she can drink water at most one time, which immediately halves her current fullness (using floor division). Determine the maximum fullness she can achieve.
Formally, you are given three integers $T$, $A$, and $B$. Starting from 0 fullness, you may add either $A$ or $B$ repeatedly as long as the resulting fullness does not exceed $T$. Optionally, one time you may apply the operation $f \rightarrow \lfloor \frac{f}{2} \rfloor$, and then resume adding fruits (each addition still cannot cause the fullness to exceed $T$). Output the maximum fullness attainable.
inputFormat
The input consists of a single line containing three space-separated integers: $T$, $A$, and $B$, where $T$ is Bessie's maximum fullness and $A$, $B$ are the fullness increases from eating an orange and a lemon respectively.
outputFormat
Output a single integer, which is the maximum fullness Bessie can achieve.
sample
10 3 4
10