Crossing the Stepping Stones (large)
InterviewTime limit2sMemory limit1024 MB
Find the smallest energy limit K such that some path from stone 1 to stone N, jumping rightward, keeps every jump cost (j-i)*(1+|Ai-Aj|) within K.
- Level
Medium7 of 10
- Topics
- Binary search, Greedy, Dynamic programming, Array
- Solved
- No attempts yet
Problem
stones are lined up in a row. The stones are given the numbers from left to right. You want to start at the leftmost stone and cross to the rightmost stone.
- You can only move to the right.
- When moving from the -th stone to the -th stone , you use units of energy.
- For each single crossing between stones, the energy you can use is at most .
Find the minimum among all ways to cross from the leftmost stone to the rightmost stone.
Input
The first line gives the number of stones , separated by spaces.
The second line gives the stone numbers , separated by spaces.
Output
Print the minimum possible among all ways to cross from the leftmost stone to the rightmost stone.
Constraints
- is an integer