#K6371. Minimize Contest Balance

    ID: 31814 Type: Default 1000ms 256MiB

Minimize Contest Balance

Minimize Contest Balance

You are given a contest where N participants are divided into rooms with K participants in each room (assume that N is divisible by K). Each participant has a skill level. The contest balance is defined as the maximum difference between the highest and lowest skill levels among all rooms.

After sorting the skills in non-decreasing order, the participants are grouped into consecutive segments of size K. For each segment, let the difference be computed as

$$d_i = a_{(i\cdot K + K -1)} - a_{(i\cdot K)}$$

and the overall contest balance is

$$balance = \max_{i=0}^{\frac{N}{K}-1} d_i$$

Your task is to compute and output the minimized contest balance.

inputFormat

The input is given via standard input (stdin) and consists of two lines. The first line contains two integers N and K separated by a space, where N is the number of participants and K is the number of participants per room. The second line contains N space-separated integers representing the skill levels of the participants.

outputFormat

Output a single integer to standard output (stdout) representing the minimized contest balance.

## sample
6 3
7 2 5 10 8 6
4

</p>