#include <iostream> #include <algorithm> using namespace std; int s[5005][5005],n,r; void sov(){ int i,j,ans=0; int x,y,z; cin>>n>>r; r=min(r,5001); for(i=1;i<=n;i++) cin>>x>>y>>z,s[x+1][y+1]+=z; for(i=1;i<=5003;i++) for(j=1;j<=5003;j++) s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1]; for(i=r;i<=5003;i++) for(j=r;j<=5003;j++) ans=max(ans,s[i][j]+s[i-r][j-r]-s[i-r][j]-s[i][j-r]); cout<<ans; } main(){ sov(); }
标签:前缀,5005,int,二维,P2280,include From: https://www.cnblogs.com/towboa/p/16934392.html