Google Kickstart 2019 Round F Flattening
First, we find the major height $H_k$ from each position $i$ to each position $j$. The change is not more than K, it means it will have at most $K+1$ group. We start counting the minimum number of steps needed to position j if we allow $g$ group exists. Follow this sequence of operation, we start from $g=0$ until we get $g=k+1$.