Sangkeun Tower
Time limit1sMemory limit128 MB
For each elevator, find the minimum floor above 0 reachable using exactly n button presses (up/down moves), never going below 0, then take the overall minimum across elevators.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Brute force, Math
- Solved
- No attempts yet
Problem
Sangkeun used his leftover money to build a very tall building called “Sangkeun Tower”.
Sangkeun Tower has elevators. Each elevator has two buttons. For the -th elevator, one button goes up floors and the other button goes down floors.
The bottom floor (the lobby) of Sangkeun Tower is floor 0, and the floors above it are numbered with increasing natural numbers (floor 1, floor 2, and so on). An elevator can never go below floor 0 (underground), and the building is so tall that it has no top.
Sangkeun is standing in the lobby. He now picks exactly one elevator and boards it. Once he boards an elevator, he cannot switch to another one. Write a program that finds the lowest floor (excluding the lobby) he can reach by pressing the buttons of the chosen elevator exactly times.
Input
The first line contains and . (, ) Each of the next lines contains and for one elevator, separated by a space. ()
Output
Print the lowest floor that can be reached by pressing an elevator's buttons exactly times. The lobby (floor 0) is excluded.