#C4784. Minimize the Maximum Element
Minimize the Maximum Element
Minimize the Maximum Element
You are given a sequence of integers along with an allowed number of operations. In each operation, if the smallest element is strictly smaller than the largest element, you remove both the smallest and the largest elements and replace them with a single value, computed as the difference between the largest element and the smallest element. Your task is to minimize the maximum element in the sequence by applying at most k operations.
For each query, you are given:
- n: The number of elements in the sequence.
- k: The maximum number of operations you can perform.
- v: The sequence of integers.
After performing the operations (only if the smallest element is less than the largest element), output the minimized maximum element of the sequence.
The formula for each operation can be written as: $$ new\_value = \text{largest} - \text{smallest} $$
inputFormat
The input is read from stdin and has the following format:
- The first line contains a single integer T, representing the number of queries.
- Each of the next T lines contains a query. Each query starts with two integers n and k, where n is the number of elements in the sequence and k is the number of operations allowed, followed by n space-separated integers representing the sequence.
outputFormat
For each query, output a single line to stdout containing the minimized maximum element in the sequence after performing the operations.
## sample2
3 2 5 3 8
4 3 10 8 5 7
5
4
</p>