## UTS Open '21 P6 - Terra Mater

View as PDF

Points: 25 (partial)
Time limit: 4.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

In an alternate universe, you are the Earth god tasked with the responsibility of managing terrain safety. Your most pressing duty is that of hills lined up in a single row. You know that the hill from the left currently has height . In your world, the danger factor of any terrain is the maximum difference in height between any adjacent hills. Formally, the danger factor is defined as . To minimize the danger factor, you are allowed to change the height of at most hills, each to any positive integer of your choosing (the resulting height may be different for each hill). Please find the minimum possible danger factor after doing so. To ensure the integrity of your solution, there may be multiple test cases.

#### Constraints

For this problem, you will NOT be required to pass the sample case in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

The sum of over all test cases will not exceed .

No further constraints.

#### Input Specification

The first line contains an integer , the number of test cases. The next lines will describe the test cases.

The first line of each test case contains integers and , the number of hills and the number of hills whose height you may change.

The second line of each test case contains integers , the height of the hill from the left.

#### Output Specification

For each test case output one integer on its own line, the minimum possible danger factor after changing the height of at most hills.

#### Sample Input

2
6 2
1 3 7 2 3 6
7 4
1 5 8 5 5 7 8

#### Sample Output

2
0

#### Explanation

For the first test case, one possible solution is to change the height of the third hill to and the height of the sixth hill to , as depicted in the diagram above. The resulting danger factor is .

For the second test case, the optimal solution is to change the heights of the first, third, sixth, and seventh hills all to . Since all hills have the same height now, the resulting danger factor is .