#P1798. Efficient Box Moving
Efficient Box Moving
Efficient Box Moving
Little Ming is moving out and needs help transporting boxes. He lives on the N-th floor. In total, K people must help move M big boxes to the N-th floor. Initially, all M boxes are on the 1st floor, but a chaotic moving process made the work inefficient. After careful observation, everyone agreed on the following efficient method:
- Each person moves one floor per minute.
- Anyone moving upward always carries a box, and anyone moving downward carries no box.
- Upon reaching the N-th floor, a person immediately drops off the box and turns around to go downward.
- Upon reaching the 1st floor, if there is any remaining box, the person immediately picks one up and turns to go upward.
- If an upward-moving person (with a box) and a downward-moving person (without a box) meet in the corridor, the upward mover passes the box to the downward mover; both then immediately reverse directions. That is, the person who was going upward now goes downward without a box, while the person who was going downward now carries the box upward.
Your task is to compute the minimum time needed to move all M boxes from floor 1 to floor N using these rules.
Note: All persons start at floor 1 at time 0. When a person picks up a box they immediately start moving upward. The minimal time for the first batch of boxes (up to min(M, K)) is N-1 minutes. For any remaining boxes, each full cycle (a downward trip from the top plus an upward trip with a box) takes 2×(N-1) minutes. Thus, the answer can be expressed as:
$$T = \begin{cases} N-1, & \text{if } M \le K,\\[1mm] (N-1)+2(N-1) \cdot \left\lceil\frac{M-K}{K}\right\rceil, & \text{if } M > K. \end{cases} $$inputFormat
The input consists of a single line with three integers N, K and M separated by spaces:
- N (2 ≤ N ≤ 109): the floor number where boxes need to be delivered.
- K (1 ≤ K ≤ 105): the number of people helping.
- M (1 ≤ M ≤ 109): the number of boxes.
outputFormat
Output a single integer representing the minimum time (in minutes) required to move all boxes to the N-th floor under the described efficient method.
sample
2 1 2
3