eolymp
bolt
Try our new interface for solving problems

Balls

The classic Two Glass Balls brain-teaser is often posed as: "\textit{Given two identical glass spheres, you would like to determine the lowest floor in a }\textit{\textbf{100}}\textit{-story building from which they will break when dropped. Assume the spheres are undamaged when dropped below this point. What is the strategy that will minimize the worst-case scenario for number of drops?}" Suppose that we had only one ball. We'd have to drop from each floor from \textbf{1} to \textbf{100} in sequence, requiring \textbf{100} drops in the worst case. Now consider the case where we have two balls. Suppose we drop the first ball from floor n. If it breaks we're in the case where we have one ball remaining and we need to drop from floors \textbf{1} to \textbf{n-1} in sequence, yielding \textbf{n} drops in the worst case (the first ball is dropped once, the second at most \textbf{n-1} times). However, if it does not break when dropped from floor \textbf{n}, we have reduced the problem to dropping from floors \textbf{n+1} to \textbf{100}. In either case we must keep in mind that we've already used one drop. So the minimum number of drops, in the worst case, is the minimum over all \textbf{n}. You will write a program to determine the minimum number of drops required, in the worst case, given \textbf{B} balls and an \textbf{M}-story building. \InputFile The first line of input contains a single integer \textbf{P}, (\textbf{1} ≤ \textbf{P} ≤ \textbf{1000}), which is the number of data sets that follow. Each data set consists of a single line containing three (\textbf{3}) decimal integer values: the problem number, followed by a space, followed by the number of balls \textbf{B}, (\textbf{1} ≤ \textbf{B} ≤ \textbf{50}), followed by a space and the number of floors in the building \textbf{M}, (\textbf{1} ≤ \textbf{M} ≤ \textbf{1000}). \OutputFile For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the minimum number of drops needed for the corresponding values of \textbf{B} and \textbf{M}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
1 2 10
2 2 100
3 2 300
4 25 900
Output example #1
1 4
2 14
3 24
4 10
Source Greater New York Regional 2009