Milk Pails
InterviewTime limit2sMemory limit512 MB
Combine pours of sizes X and Y without exceeding M to get as close to M as possible.
- Level
Easy2 of 10
- Topics
- Brute force
- Solved
- No attempts yet
Problem
Farmer John has an order for exactly units of milk () that he must fill right now. His milking machine just broke, so all he has are three pails of integer sizes , , and (). All three pails start empty. He may perform the following two operations any number of times, in any order.
- Fill the smallest pail (size ) to the top with units of milk and pour it into the size- pail. He may do this only if the size- pail does not overflow.
- Fill the medium pail (size ) to the top with units of milk and pour it into the size- pail. He may do this only if the size- pail does not overflow.
He may not be able to fill the size- pail all the way. Find the maximum amount of milk he can put into that pail.
Input
The first and only line contains , , and , separated by spaces.
Output
Print the maximum amount of milk Farmer John can put into the size- pail.
Note
For , , and , pouring the size-17 pail three times and the size-25 pail once collects 76 units of milk.