#P3143. Bessie's Diamond Display
Bessie's Diamond Display
Bessie's Diamond Display
Bessie the cow, always a fan of shiny objects, has taken up diamond mining in her spare time!
She has collected \(N\) diamonds of various sizes and wants to showcase some of them in two display cases in her barn. However, to keep the displays aesthetically pleasing, she decides that no two diamonds in the same case can have a size difference greater than \(K\) (diamonds with a size difference exactly equal to \(K\) are allowed).
Given \(N\), \(K\) and the sizes of the diamonds, determine the maximum total number of diamonds that can be arranged in the two display cases.
Input Format: The first line contains two integers \(N\) and \(K\). The following \(N\) lines each contain a single integer representing a diamond's size.
Output Format: Output a single integer, the maximum number of diamonds that Bessie can display in the two cases.
inputFormat
The first line contains two integers \(N\) (\(1 \leq N \leq 50000\)) and \(K\) (\(K \ge 0\)). The next \(N\) lines each contain an integer representing the size of one diamond.
outputFormat
Output a single integer: the maximum number of diamonds Bessie can display in both cases under the given conditions.
sample
7 3
10
5
1
12
9
5
14
5