#t132. 宝箱
宝箱
Treasure Chests
Problem Description
Little Yang found treasure chests; the -th chest has value .
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 and the minimum value is ; he must ensure , 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 , as described.
The second line contains positive integers , 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, , , and the chest values are . We can choose the three chests of values (for example the chests at indices ). Among them the maximum value is and the minimum is ; the difference , so the backpack does not break, and the total value is . Trying any other combination (e.g. only , or ) cannot yield a larger total, so the maximum total value is .
Constraints
For all data, , , and are guaranteed.