On a hot summer day, Bessie the cow feels lazy. She wants to pick a starting point in her field so that she can reach as much grass as possible within a short walk.
The field has N grass patches (1≤N≤100000). Patch i holds gi units of grass (1≤gi≤10000) at a distinct point (xi,yi) (0≤xi,yi≤1000000). Bessie chooses one point in the field as her start (it may coincide with a patch or use non-integer coordinates). She wants the maximum total grass within Manhattan distance K of that point (1≤K≤2000000).
Each step moves 1 unit north, south, east, or west. For example, (0,0) to (3,2) needs 5 steps. A step may be split: half a unit north plus half a unit east still counts as one step.
Print one integer: the maximum grass Bessie can reach within K steps when she picks the best start.
Rotate coordinates to (u,v)=(x+y,x−y). A Manhattan ball becomes a box with ∣u−u0∣≤K and ∣v−v0∣≤K. Sort by u, slide a window of width at most 2K, and within each window slide on v the same way.