## Min amplitude

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

• haitamoi51  commented on Nov. 19, 2022, 12:03 a.m.

What does it mean, changing an element?

• youssefboumhaout  commented on Nov. 19, 2022, 7:35 a.m.

Mean we can change the value of A[i] to any other value that we want.

For example : A[i] = 10 we can change A[i] to 2 so A[i] = 2.

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

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

• 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