The Experimenter
Time limit1sMemory limit1024 MB
Find the minimum worst-case number of floors climbed to locate the lowest floor where a transistor breaks, given n floors and m transistors.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Recursion
- Solved
- No attempts yet
Statement
An elderly professor became interested in testing the strength of the KD521(2) transistor. Unfortunately, he could not recruit any of his colleagues, so he has to run the measurements himself. The professor is not discouraged.
In a cabinet he found transistors of this model left over from old times, and he decided to use them for experiments.
After some thought, he chose the following method. The professor climbs the fire escape and drops transistors from different floors. This way he plans to find the minimum floor from which a transistor breaks when it falls. The professor is sure that a transistor always breaks when dropped from the last floor, but a drop from head height (when the professor is on the first floor) does no harm.
All transistors are identical. If a transistor breaks when dropped from some floor, it also breaks when dropped from every higher floor.
A broken transistor cannot be used again. A transistor that survives a fall can be reused. To pick up an intact transistor, the professor must go down to the first floor. Once he is on the first floor, he can pick up all the transistors lying there.
The professor's years are starting to show, so he wants to minimize the total distance he must climb the stairs. Age also brings some advantages: without his glasses, the professor can tell from any floor whether a transistor broke.
Initially the professor is on the first floor and has transistors. The building he lives in has floors.
Find the minimum number of floors the professor will have to climb up the stairs in the worst case during the experiments.
Input
The input file contains two integers: the height of the building () and the number of transistors ().
Output
The output file contains a single number: the minimum distance in floors that the professor will have to climb up the stairs in the worst case during the experiment.
Hint
In the first sample, the professor's optimal behavior is as follows. First he climbs two floors and drops a transistor from the third floor. If it breaks, he goes down to the second floor and tries dropping a transistor from there. If it breaks from the second floor too, the result is 2, otherwise the result is 3. If the transistor does not break from the third floor, he climbs to the fourth floor and drops a transistor from there. If it breaks, the result is 4, otherwise the result is 5. In the worst case he has to climb three floors.
In the second sample, nothing needs to be dropped, and the result of the study is 2.