PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000303. Tối đa khoảng cách giữa các số được chọn (Maximize Score of Numbers in Ranges)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối đa khoảng cách giữa các số được chọn (Maximize Score of Numbers in Ranges)

Maximize Score of Numbers in Ranges

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integer intervals [ai,ai+d][a_i,a_i+d], choose one integer xix_i from each. The score is min⁡i<j∣xi−xj∣\min_{i<j}|x_i-x_j|. Maximize this score. Chosen values may coincide.

Input

First line: n,dn,d. Second line: nn integers aia_i.

Output

Print the maximum score.

Subtasks

  • Subtask 1 (20 points): 2≤n≤62\le n\le6; 0≤d≤40\le d\le4; 0≤ai≤200\le a_i\le20.
  • Subtask 2 (30 points): 2≤n≤1052\le n\le10^5; d=0d=0; 0≤ai≤1090\le a_i\le10^9.
  • Subtask 3 (50 points): 2≤n≤1052\le n\le10^5; 0≤d,ai≤1090\le d,a_i\le10^9.

Examples

Input 1

3 2
6 0 3

Output 1

4

Explanation

Choose 8,0,4 in the original interval order. A gap of 5 would require a third sorted value at least 10, beyond 8.