Programming contests

ACM ICPC programozó csapatverseny, házi forduló, 2018. október 31.

October 31, 2018 10:10 AM – October 31, 2018 3:10 PM

Computer Science

Vera has N integers a1, …, aN. A margin is a nonnegative integer L such that it is possible to choose N integers x1, …, xN such that for all i, 1 ≤ i ≤ N, the interval [xixi + L] contains at least K of Vera's integers and also contains ai.

Compute the minimum possible margin.

Input Specification

Line 1 contains integers N and K (1 ≤ K ≤ N ≤ 2 · 105).

Line 2 contains N integers, a1, …, aN (–109 ≤ ai ≤ 109).

Output Specification

Print one line with one integer, the minimum possible margin.

Sample Input

  1. 5 3
  2. 1 -2 10 5 4
download as text file

Output for Sample Input

  1. 6
download as text file

Note

For the example, one possible solution is to choose x1 = –1, x2 = –2, x3 = 4, x4 = 0, x5 = 0, which is illustrated below:

University of Debrecen; Faculty of Informatics; v. 03/01/2019