Problem
You need to go up n floors (from floor 0 to floor n). You may:
-
Take the elevator first (at most once, only at the start)
for
k
floors, where
0 ≤ k ≤ n
.
-
For each elevator floor traveled:
-
You
gain
e1
energy.
-
You spend
t1
time.
-
After riding
k
floors, your energy is
E = k * e1
.
-
Then climb the remaining
n - k floors by stairs
.
-
For each stair floor climbed:
-
If your current energy before climbing that floor is
E
, the time spent on that floor is:
⌈c/E⌉
- After climbing that floor, your energy decreases by `e2`:
`E := E - e2`
-
Energy must never become negative
, meaning before every stair step you must have
E ≥ e2
(so that after subtracting
e2
you still have
E ≥ 0
).
Your task is to choose k to minimize the total travel time.
Input
Five integers:
-
n
: number of floors to go up
-
e1
: energy gained per elevator floor
-
t1
: time per elevator floor
-
e2
: energy spent per stair floor
-
c
: constant used in stair time formula
Output
Return the minimum possible total time to reach floor n.
-
If it is
impossible
to reach floor
n
for any
k
(i.e., you can’t complete the stair portion without energy going negative), return
-1
.
Notes / Clarifications
-
The elevator can be taken
only once and only before any stair climbing
.
-
Stair time uses the
current energy before
spending
e2
for that floor.
-
Use 64-bit arithmetic where appropriate.