BZOJ1218 激光炸弹

二维前缀和 

#include<cstdio>
#include<algorithm>
using namespace std;
int s[5005][5005];
int main()
{
    int n, r, x, y, v, ans = 0;
    scanf("%d%d",&n,&r);
    for(int i = 1; i <= n; i++){
        scanf("%d%d%d",&x,&y,&v);
        s[x+1][y+1] += v;
    }
    for(int i = 1; i <= 5001; i++){
        for(int j = 1; j <= 5001; j++){
            s[i][j] = s[i-1][j]+s[i][j-1]-s[i-1][j-1]+s[i][j];
        }
    }
    for(int i = r; i <= 5001; i++){
        for(int j = r; j <= 5001; j++){
            ans = max(ans,s[i][j]-s[i-r][j]-s[i][j-r]+s[i-r][j-r]);
        }
    }
    printf("%d\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/kkjy_00/article/details/86912689
今日推荐