This page is still under construction.

Parts of this page are still being built. What you see may change.

Crossing the Stepping Stones (large)

Interview

Time limit2sMemory limit1024 MB

Summary
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

NN stones are lined up in a row. The stones are given the numbers A1,A2,...,Ai,...,ANA_{1}, A_{2}, ..., A_{i}, ..., A_{N} from left to right. You want to start at the leftmost stone and cross to the rightmost stone.

  1. You can only move to the right.
  2. When moving from the ii-th stone to the jj-th stone (i<j)(i < j), you use (j−i)×(1+∣Ai−Aj∣)(j - i) \times (1 + |A_{i} - A_{j}|) units of energy.
  3. For each single crossing between stones, the energy you can use is at most KK.

Find the minimum KK among all ways to cross from the leftmost stone to the rightmost stone.

Input

The first line gives the number of stones NN, separated by spaces.

The second line gives the NN stone numbers AiA_{i}, separated by spaces.

Output

Print the minimum possible KK among all ways to cross from the leftmost stone to the rightmost stone.

Constraints

  • 2≤N≤5,0002 \le N \le 5,000
  • 1≤Ai≤1,000,0001 \le A_{i} \le 1,000,000
  • AiA_{i} is an integer

Examples2

  1. Example 1

    Input
    5
    1 4 1 3 1
    
    Expected output
    2
    
  2. Example 2

    Input
    5
    1 5 2 1 6
    
    Expected output
    6