前缀和 大暴力啊
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdlib> 5 #include<cmath> 6 #include<queue> 7 #include<algorithm> 8 #include<vector> 9 #define M 5009 10 #define EPS 1e-10 11 #define MO 10000 12 #define ll long long 13 using namespace std; 14 ll read() 15 { 16 char ch=getchar(); 17 ll x=0,f=1; 18 for(;ch<'0'||ch>'9';ch=getchar()) 19 if(ch=='-') 20 f=-1; 21 for(;ch>='0'&&ch<='9';ch=getchar()) 22 x=x*10+ch-'0'; 23 return x*f; 24 } 25 int n,sum[M][M],r,x[M],y[M]; 26 int main() 27 { 28 n=read(); 29 r=read(); 30 for(int i=1;i<=n;i++) 31 { 32 x[i]=read()+1; 33 y[i]=read()+1; 34 sum[x[i]][y[i]]+=read(); 35 } 36 for(int i=1;i<=5001;i++) 37 for(int j=1;j<=5001;j++) 38 sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]; 39 r--; 40 int mx=0; 41 for(int i=1;i<=5001-r;i++) 42 for(int j=1;j<=5001-r;j++) 43 mx=max(mx,sum[i+r][j+r]-sum[i-1][j+r]-sum[i+r][j-1]+sum[i-1][j-1]); 44 printf("%d ",mx); 45 return 0; 46 }