Convicts in jail

There are n jails beside a straight road. You know the position (in km)
of each jail. Please choose the jails where to confine m dangerous
convicts in order to maximize the minimum distance between two convicts.

For instance, consider five jails at positions 1, 10, 23, 42 and 50, and
three convicts. Here, the optimum solution is to use the first, third
and fifth jail, with a minimum distance of 22.

Input

Input consists of several cases, each with m and n, followed by the
positions of the n jails. Assume 2 ≤ m ≤ n ≤ 10⁴, and that the n
positions are different and between 0 and 10⁹.

Output

For every case, print the largest possible distance between the two
nearest convicts.

Problem information

Author: Javier Nistal

Generation: 2026-01-25T11:56:09.163Z

© Jutge.org, 2006–2026.
https://jutge.org
