You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
878 B
C++

#include <cstdio>
#include <cctype>
inline int max(int a, int b) { return a > b ? a : b; }
inline void readInt(int &x)
{
int ch = x = 0;
while (!isdigit(ch = getchar()));
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
}
int a[5010][5010];
int main()
{
int n, r;
readInt(n), readInt(r);
for (int i = 0, x, y, z; i < n; i++)
{
readInt(x), readInt(y), readInt(z);
a[x + 1][y + 1] += z;
}
for (int i = 1; i < 5010; i++)
for (int j = 1; j < 5010; j++)
a[i][j] += a[i][j - 1];
for (int i = 1; i < 5010; i++)
for (int j = 1; j < 5010; j++)
a[i][j] += a[i - 1][j];
int ans = 0;
for (int i = r; i < 5010; i++)
for (int j = r; j < 5010; j++)
ans = max(ans, a[i][j] - a[i][j - r] - a[i - r][j] + a[i - r][j - r]);
printf("%d", ans);
return 0;
}