AcWing 99. 激光炸弹
原题链接
简单
作者:
07kzs
,
2019-07-29 13:53:36
,
所有人可见
,
阅读 864
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
int a[maxn][maxn];
int main(void) {
int n=2, r=1;
cin>>n>>r;
int x, y, c, maxX=r, maxY=r;
for(int i = 1; i <= n; i++) {
cin>>x>>y>>c;
a[++x][++y] += c;
maxX = max(maxX, x);
maxY = max(maxY, y);
}
for(int i = 1; i <= maxX; i++){
for(int j = 1; j <= maxY; j++){
a[i][j] = a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1] + a[i][j];
}
}
int ans = -2147483647;
for(int i = r; i <= maxX; i++){
for(int j = r; j <= maxY; j++){
ans = max(ans, a[i][j] - a[i - r][j] - a[i][j - r] + a[i - r][j - r]);
}
}
cout<<ans;
return 0;
}