题解:二维前缀和,枚举正方形右下端点
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int u=5001; int ans; int n,r; int s[u+1][u+1]; int main(){ scanf("%d%d",&n,&r); while(n--){ int x,y,z; scanf("%d%d%d",&x,&y,&z); s[x+1][y+1]+=z; } for(int i=1;i<=u;++i){ for(int j=1;j<=u;++j){ s[i][j]=s[i][j]+s[i][j-1]+s[i-1][j]-s[i-1][j-1]; } } for(int i=r;i<=u;++i){ for(int j=r;j<=u;++j){ int tm=s[i][j]-s[i][j-r]-s[i-r][j]+s[i-r][j-r]; ans=max(ans,tm); } } cout<<ans<<endl; return 0; }
原文地址:https://www.cnblogs.com/zzyer/p/8456669.html
时间: 2024-11-08 13:35:29