RT。
代码:
var
n,m,i,j,x,y,z,max:longint;
s:Array[-3..5005,-3..5005]of longint;
begin
readln(n,m);
for i:=1 to n do
begin
readln(x,y,z);
s[x,y]:=z;
end;
for i:=1 to 5001 do
for j:=1 to 5001 do
s[i,j]:=s[i,j-1]+s[i-1,j]-s[i-1,j-1]+s[i,j];
if m>=n then begin writeln(s[n,n]);halt; end;
for i:=0 to 5001-m do
for j:=0 to 5001-m do
if s[i+m-1,j+m-1]-s[i-1,j+m-1]-s[i+m-1,j-1]+s[i-1,j-1]>max then
max:=s[i+m-1,j+m-1]-s[i-1,j+m-1]-s[i+m-1,j-1]+s[i-1,j-1];
writeln(max);
end.
详情:
