This page is still under construction.

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

Crossing the Stepping Stones (small)

Interview

Time limit1sMemory limit1024 MB

Summary
Given stones with values A_i, decide if you can reach the last stone when each jump i to j costs (j-i)*(1+|A_i-A_j|) and no jump may exceed K.
Level

Medium5 of 10

Topics
Dynamic programming, Array, Implementation, Brute force
Solved
No attempts yet

Problem

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

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

Determine whether you can cross from the leftmost stone to the rightmost stone.

Input

The first line gives the number of stones NN and the maximum energy KK you can use, separated by a space.

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

Output

If you can move to the rightmost stone, print YES. If you cannot, print NO.

Constraints

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

Examples2

  1. Example 1

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

    Input
    5 3
    1 5 2 1 6
    
    Expected output
    NO