Under construction

Still being built. Things may change

Closet

Interview

Time limit5sMemory limit1024 MB

Summary
Find the smallest tolerance x so that removing at most M clothes leaves a sequence that rises then falls, with each adjacent step at most x.
Level

Medium6 of 10

Topics
Binary search, Dynamic programming, Array
Solved
No attempts yet

Problem

Taein's closet has NN clothes hanging in a row. The color of the ii-th piece from the left is cic_i.

Taein considers the closet beautiful if there is an integer kk (1≤k≤N1 \le k \le N) such that c1≤c2≤⋯≤ck≥ck+1≥⋯≥cNc_1 \le c_2 \le \cdots \le c_k \ge c_{k+1} \ge \cdots \ge c_N.

Arranging the closet into a beautiful state is quite a hassle. So Taein decided to remove at most MM clothes from the closet so that the remaining clothes become nearly beautiful.

After removing at most MM clothes, let LL be the number of remaining clothes and let djd_j be the color of the jj-th piece from the left. Taein treats two adjacent pieces as the same color if their color difference is at most xx. The closet is nearly beautiful if there is an integer kk (1≤k≤L1 \le k \le L) such that the following hold.

  • dj−dj+1≤xd_j - d_{j+1} \le x for every integer jj with 1≤j<k1 \le j < k.
  • dj+1−dj≤xd_{j+1} - d_j \le x for every integer jj with k≤j<Lk \le j < L.

Find the smallest non-negative integer xx such that the closet can be made nearly beautiful by removing at most MM clothes.

Input

The first line contains two integers NN and MM. The second line contains NN integers c1,c2,…,cNc_1, c_2, \ldots, c_N, separated by spaces.

Output

Print the smallest xx (x≥0x \ge 0) such that the closet can be made nearly beautiful.

Constraints

  • 1≤N≤1051 \le N \le 10^5
  • 0≤M≤N0 \le M \le N
  • 1≤ci≤1091 \le c_i \le 10^9 (1≤i≤N1 \le i \le N)

Hint

When x=2x=2, removing the 5th and 9th pieces from the left makes the closet nearly beautiful. No smaller xx can make the closet nearly beautiful.

Examples1

  1. Example 1

    Input
    10 2
    4 2 7 15 3 11 12 10 2 6
    
    Expected output
    2