#t132. 宝箱

宝箱

Treasure Chests

Problem Description

Little Yang found nn treasure chests; the ii-th chest has value aia_i.

Little Yang may choose some chests to put into his backpack and take away, but his backpack is special: suppose among the chosen chests the maximum value is xx and the minimum value is yy; he must ensure x−y≤kx - y \le k, otherwise the backpack breaks.

Little Yang wants to know the maximum total value of chests he can take away without breaking the backpack.

Input Format

The first line contains two positive integers n,kn, k, as described.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n, the values of the chests.

Output Format

Output one integer: the maximum total value of chests that can be taken.

Sample Input

5 1
1 2 3 1 2

Sample Output

7

Sample Explanation

In the sample, n=5n=5, k=1k=1, and the chest values are 1,2,3,1,21, 2, 3, 1, 2. We can choose the three chests of values 2,2,32, 2, 3 (for example the chests at indices 2,4,32, 4, 3). Among them the maximum value is 33 and the minimum is 22; the difference 3−2=1≤k3-2=1 \le k, so the backpack does not break, and the total value is 2+2+3=72+2+3=7. Trying any other combination (e.g. only 33, or 1,1,2,21,1,2,2) cannot yield a larger total, so the maximum total value is 77.

Constraints

For all data, 1≤n≤10001\le n\le 1000, 0≤k≤10000\le k\le 1000, and 1≤ai≤10001\le a_i\le 1000 are guaranteed.