Make Differences at Least
Time limit1sMemory limit1024 MB
Given a sequence A and an integer M, find the fewest terms to change so every adjacent difference is at least M, or report -1 if impossible.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Segment tree, Array
- Solved
- No attempts yet
Problem
Dongwoo is analyzing a sequence of length . In one operation, Dongwoo can change one term of the sequence to any integer he wants. Dongwoo hates doing extra work, so he wants to make every difference between adjacent terms at least using the fewest possible operations. That is, the goal is for all . Help Dongwoo find the minimum number of operations needed.
Input
The first line contains two integers () and (), separated by a space.
The second line contains integers (), separated by spaces.
Output
Print the minimum number of operations needed to make every difference between adjacent terms at least .
If it is impossible, print -1.