Crossing the Stepping Stones (small)
InterviewTime limit1sMemory limit1024 MB
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
stones are arranged in a line. The stones are given the numbers from left to right. You want to cross from the leftmost stone to the rightmost stone.
- You can only move to the right.
- Moving from the -th stone to the -th stone costs energy.
- For each crossing between stones, you can use at most energy.
Determine whether you can cross from the leftmost stone to the rightmost stone.
Input
The first line gives the number of stones and the maximum energy you can use, separated by a space.
The second line gives the numbers of the stones, separated by spaces.
Output
If you can move to the rightmost stone, print YES. If you cannot, print NO.
Constraints
- is an integer
- is an integer