Building Heights
Time limit2sMemory limit512 MB
With building 1 at height 0, adjacent heights differing by at most K, and M caps, find the maximum achievable height of any building.
- Level
Medium6 of 10
- Topics
- Greedy, Implementation, Math, Prefix sum
- Solved
- No attempts yet
Problem
You put up new buildings in a row. Number them 1 to from the left.
The heights obey these limits.
- Every building height is a non-negative integer.
- Building 1 has height 0.
- Two neighboring buildings differ in height by at most .
- Building has height at most .
Write a program that finds the height of the tallest building you can put up while every limit holds.
Input
The first line contains and . ()
The second line contains , the number of buildings that carry a height cap. ()
If is at least 1, the third line contains and the fourth line contains , separated by spaces. (, , ) If is 0, the third and fourth lines are not given.
Output
Print the height of the tallest building you can put up while every limit holds.