Tower
Time limit2sMemory limit1024 MB
Given blocked step ranges on a staircase, single steps costing A seconds and D-step jumps costing B seconds, find the minimum time to reach each queried step X.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, Math
- Solved
- No attempts yet
Problem
The IOI Tower is an extremely tall tower with a staircase for climbing. The staircase has steps, numbered from the bottom as step , step , and so on. JOI-kun is on step and wants to climb the staircase. JOI-kun can ascend by taking one of the following 2 actions. Descending is not allowed.
- Ascend 1 step. This action takes seconds.
- Jump from the current step to the step steps above, skipping the steps in between. This action takes seconds.
Some steps are under construction and cannot be stepped on. There are constructions, and the -th construction covers steps .
The IOI Tower has rooms numbered from to . Room can be entered from step . For each room, determine whether JOI-kun can reach step and, if so, the minimum time needed to get there.
Input
The first line contains and . The second line contains , , and . Each of the next lines contains and . Each of the next lines contains .
Output
Output lines. On line , print the minimum number of seconds needed to reach step . If step is unreachable, print -1.
Constraints
- ()
- ()
- ()
- All given values are integers.