cswork / OAOpen practice workspace

MicrosoftOA #19

Shortest Board Length to Cover Holes

Estimated MediumJudge-ready

Topics (AI-labelled)Binary SearchGreedy

The two boards must have the same positive integer length L; a board placed at X covers the closed interval [X,X+L]. Find the minimum L needed to cover all distinct hole coordinates. The boards may overlap, and one of them may cover no hole.

Input

The first line contains N (1..100000), and the second line contains N distinct coordinates (0..10⁹), possibly unsorted.

Output

Output a single integer, the answer.

Example 1

Input:

3
11 20 15

Output:

4

Example 2

Input:

4
15 20 9 11

Output:

5

Example 3

Input:

1
9

Output:

1

Example notes

Example 1: one board covers 11..15 and the other covers 20, so the minimum length is 4.

Example 2: split the holes into 9..11 and 15..20; the larger span is 5, so the answer is 5.

Example 3: even with only one hole the length must be positive, so the answer is 1.

Editorial

Loading solution…