#K4596. Minimizing Fairness in Prize Distribution

    ID: 27869 Type: Default 1000ms 256MiB

Minimizing Fairness in Prize Distribution

Minimizing Fairness in Prize Distribution

Anna is organizing a prize distribution contest. She has N prizes with given values and M participants. She wants to distribute prizes in a way that minimizes the difference between the maximum and minimum total prize value received by any participant. More formally, after selecting M prizes from the sorted list, the fairness value is defined as the difference between the largest and smallest prize values among the selected prizes.

Your task is to help Anna by computing the minimized fairness value for each test scenario. The value will be computed as:

\(\text{min_diff} = \min_{0 \leq i \leq N-M}(\text{prizes}_{i+M-1} - \text{prizes}_{i})\)

Read the input from stdin and output the results to stdout.

inputFormat

The first line contains an integer T, the number of test cases. Each test case is described as follows:

  • The first line of each test case contains two integers N and M, where N is the number of prizes and M is the number of prizes to be selected.
  • The second line contains N space-separated integers, representing the values of the prizes.

outputFormat

For each test case, output a single integer on a new line, representing the minimized fairness value.

## sample
2
5 2
8 4 3 2 5
4 3
1 1 1 1
1

0

</p>