luoguP2280 [HNOI2003]激光炸弹
luoguP2280 [HNOI2003]激光炸弹
题面
题解
二维前缀和
#include<bits/stdc++.h> using namespace std; const int MAXN = 5000 + 10; inline int read() { int f=1,x=0; char ch; do { ch=getchar(); if(ch=='-') f=-1; }while(ch<'0'||ch>'9'); do { x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); }while(ch>='0'&&ch<='9'); return f*x; } int t,r; int sum[MAXN][MAXN]; int main() { t=read();r=read(); for(int i=1;i<=t;i++) { int x=read(),y=read(),v=read(); sum[x+1][y+1]=v; } for(int i=1;i<=5000 + 1;i++) for(int j=1;j<=5000 + 1;j++) sum[i][j]=sum[i-1][j]+sum[i][j-1]+sum[i][j]-sum[i-1][j-1]; int ans=0; for(int i=0;i<=5000 + 1-r;i++) for(int j=0;j<=5000 + 1-r;j++) ans=max(ans,sum[i+r][j+r]-sum[i+r][j]-sum[i][j+r]+sum[i][j]); cout<<ans<<endl; }