AcWing 99. 激光炸弹
原题链接
简单
作者:
Value
,
2020-07-07 16:45:45
,
所有人可见
,
阅读 569
#include <iostream>
using namespace std;
const int N = 5010;
int s[N][N];
int main(){
int n, r; cin >> n >> r;
r = min(5001, r);
while(n -- ){
int x, y, v; cin >> x >> y >> v;
x ++ , y ++ ;
s[x][y] += 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];
}
}
int res = 0;
for(int i = r; i <= 5001; i ++ ){
for(int j = r; j <= 5001; 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;
}