#C11920. Maximum Parcels Collection by the Robot

    ID: 41290 Type: Default 1000ms 256MiB

Maximum Parcels Collection by the Robot

Maximum Parcels Collection by the Robot

Given an array of integers positions representing the locations of parcels on a one-dimensional line and an integer k, determine the maximum number of parcels that can be collected by a robot. The robot can collect all parcels that lie within a distance of \(2k\) from its starting position. In other words, if the robot starts at a parcel located at \(x\), it can collect all parcels in the interval \([x, x+2k]\). Choose the starting parcel optimally to maximize the number of parcels collected.

inputFormat

The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the number of parcels and \(k\) defines the effective half-range of collection. The second line contains \(n\) space-separated integers representing the positions of the parcels.

outputFormat

Output a single integer representing the maximum number of parcels that the robot can collect.

## sample
7 2
1 2 3 4 5 6 7
5