link:
https://www.acwing.com/problem/content/101/
Meaning of the questions:
A novel laser bombs that can destroy all of the length of one side of the square R of the target.
There are N target on the map, with integer Xi, Yi represents the position of the target on the map, and each has a target value Wi.
Laser bombs served by satellite positioning, but it has a disadvantage that its explosion range, i.e., the side length of the sides of the square must R and x, y-axis.
If the target is located on the edge of the square blasting, the target will not be destroyed.
Seeking a bomb blew up on the map up to a total value of how much of the target.
Ideas:
Dimensional prefix and do it, then violence can be.
Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 5e3+10;
int Sum[MAXN][MAXN];
int n, r;
int main()
{
scanf("%d%d", &n, &r);
int x, y, v;
int maxx = r, maxy = r;
for (int i = 1;i <= n;i++)
{
scanf("%d%d%d", &x, &y, &v);
x++, y++;
Sum[x][y] = v;
maxx = max(maxx, x);
maxy = max(maxy, y);
}
for (int i = 1;i <= maxx;i++)
{
for (int j = 1;j <= maxy;j++)
Sum[i][j] = Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1]+Sum[i][j];
}
int res = 0;
for (int i = r;i <= maxx;i++)
{
for (int j = r;j <= maxy;j++)
{
res = max(res, Sum[i][j]-Sum[i][j-r]-Sum[i-r][j]+Sum[i-r][j-r]);
}
}
printf("%lld\n", res);
return 0;
}