AcWing 99. 激光炸弹
原题链接
简单
作者:
Java小码农
,
2021-07-20 09:10:58
,
所有人可见
,
阅读 194
C++ 代码
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 5010;
int n, m;
int s[N][N];
int main()
{
int N, R;
cin >> N >> R;
n = m = 5001;
while (N -- )
{
int x, y, w;
cin >> x >> y >> w;
x ++, y ++ ;
s[x][y] += w;
}
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
int res = 0;
for (int i = R; i <= n; i ++ )
for (int j = R; j <= m; j ++ )
res = max(res, s[i][j] - s[i - R][j] - s[i][j - R] + s[i - R][j - R]);
cout << res << endl;
return 0;
}