Given an array arr of N integers. Each array has some hardness
hardness = max abs(arr[i+1]-arr[i]) for all 1<=i<=N-1
And hardness = 0 if N<=1
You are given a number K you can change at most K elements of the array. You have to minimize the hardness of the array
Both N and K were less than 2000
where arr[i]>=-1e9 and arr[i]<=1e9








This should be easy one.
Bro, you just said a 2000 rated problem is easy. here, :skull :skull
if the array is {a1,a2,a3, ... an}, the answer is always an-a1 because the rest of the elements get canceled out, so just decrease an, and increase a1 as much as possible
Not really. Consider the array [1, 3, 2], answer here is abs(1 — 3) + abs(3 — 2) = 3. Whereas an-a1 = (2 — 1) = 1.
[REDACTED]
https://www.codechef.com/problems/KEVIN
https://codeforces.me/problemset/problem/360/B
oh wow ... how did you find these problems ??
Lets say you have fixed $$$x$$$, consider $$$dp_i,_j$$$ which means the minimum number changes needed to have this property: The hardness of prefix $$$i$$$ is smaller than $$$x$$$, and last $$$j$$$ elements were changed.
If all elements of some segment $$$[l, r]$$$ were changed, then u can make the hardness of the segment $$$[l-1, r+1]$$$ equal to $$$\lceil \frac{a_{r+1}-a_{l-1}}{r-l+3}\rceil$$$(I am not sure if this formula is correct)
Let segment $$$[l, r]$$$ be good if and only if $$$\lceil \frac{a_{r+1}-a_{l-1}}{r-l+3}\rceil \leq x$$$
You have these transitions:
$$$1.$$$ if $$$[i, i - j + 1]$$$ is good then: $$$dp_i,_j=min(dp_i,_j, dp_{i-1},_{j-1}+1)$$$
$$$2.$$$ $$$dp_i,_0=min(dp_i,_0, dp_{i-1},_{j-1})$$$
Now u can just binsearch the value $$$x$$$, and this should work in $$$O(n^2\log x)$$$