Min amplitude


Submit solution

Points: 20
Time limit: 3.0s
Memory limit: 256M

Author:
Problem type

The amplitude of an array \(A\) is the difference between largest and smallest element of that array.

Given \(A\), find the minimum amplitude you can get after changing up to \(k\) elements.

Input Specification

The first line of the input contains the number of test cases (up to \(100\)).

In the first line of each test case there are two integers \(N\) the size of \(A\) and \(k\) (\(1 \leq \)N\( \leq 10^5\)).

The next line contains \(A_i\) : the elements of \(A\) (\(1 \leq A_i \leq 10^5\)).

Output Specification

For each test case output one line with one integer : the minimum amplitude.

Sample Input

3
4 1
3 4 1 6
4 2
3 3 3 3
4 4
1 2 3 4

Sample Output

3
0
0

Comments


  • 0
    AkramElOmrani  commented on Jan. 10, 2021, 10:52 p.m.

    Change a number's value Is giving it any value we want ?


  • 1
    Asaad27  commented on May 28, 2020, 8:02 a.m.

    for those who get TLE in c++, try using scanf or fast input instead of cin, it worked for me