#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int x[N << 1], y[N << 1], w[N << 1], s[N][N];
int main()
{
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> x[i] >> y[i] >> w[i];
for (int i = 1; i <= n; i ++)
s[x[i] + 1][y[i] + 1] += w[i];
int k = 5001;
for (int i = 1; i <= k; i ++)
for (int j = 1; j <= k; j ++)
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
int ans = 0;
for (int i = 0; i <= k; i ++)
for (int j = 0; j <= k; j ++)
{
int p = max(0, i - m), q = max(0, j - m);
ans = max(ans, s[i][j] - s[p][j] - s[i][q] + s[p][q]);
}
cout << ans << '\n';
}
【板刷算进计划】激光炸弹【二维前缀和】
最新推荐文章于 2024-09-11 15:28:58 发布