传送门
真.暴力。
直接爆枚正方形左上角+前缀和优化。
N^2不虚。
uses math;
var
f:array [-5..5005,-5..5005] of longint;
r,n,i,j,ans,x,y,z:longint;
begin
read(n,r);
for i:=1 to n do begin read(x,y,z); inc(f[x,y],z); end;
for i:=0 to 5000 do
for j:=0 to 5000 do f[i,j]:=f[i,j]+f[i,j-1];
for i:=0 to 5000 do
for j:=0 to 5000 do f[i,j]:=f[i,j]+f[i-1,j];
ans:=0;
for i:=r-1 to 5000 do
for j:=r-1 to 5000 do
ans:=max(ans,f[i,j]+f[i-r,j-r]-f[i,j-r]-f[i-r,j]);
write(ans);
end.