#P2280. Laser Bomb Target Destruction

    ID: 15555 Type: Default 1000ms 256MiB

Laser Bomb Target Destruction

Laser Bomb Target Destruction

A new type of laser bomb is capable of destroying all targets inside a square of side length \(m\). There are \(n\) targets on the map with coordinates \(x_i\) and \(y_i\), each having a value \(v_i\). The bomb’s detonation is executed via satellite guidance, however, its demolition area is fixed: the square (of side length \(m\)) must have its sides parallel to the \(x\) and \(y\) axes. Note that if a target lies exactly on the boundary of the square, it will not be destroyed.

Your task is to calculate the maximum total value of targets that can be destroyed by one bomb.

Note: Multiple targets might be located at the same position.

inputFormat

The first line contains two integers \(n\) and \(m\) representing the number of targets and the side length of the bomb’s square blast zone respectively. The following \(n\) lines each contain three integers \(x_i\), \(y_i\), and \(v_i\) — the coordinates and value of the \(i\)-th target.

outputFormat

Output a single integer, the maximum total value of targets that can be destroyed by the bomb.

sample

3 3
1 1 10
2 2 20
3 3 30
60

</p>