WA on #9
查看原帖
WA on #9
932938
qianyichen20120322楼主2025/1/21 19:36
#include <bits/stdc++.h>
using namespace std;
int n, m, maxx = -1, maxy = -1;
int a[5005][5005];
int f[5005][5005];
int main() {
	cin >> n >> m;
	int t = n;
	while (t--) 
	{
		int x, y, v;
		cin >> x >> y >> v;
		a[x + 1][y + 1] += v;
		maxx = max(maxx, x+1);
		maxy = max(maxy, y+1);
	}
	maxx++;
	maxy++;
	for (int i = 1; i <= maxx; i++) 
	{
		for (int j = 1; j <= maxy; j++) 
		{
			f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + a[i][j];
		}
	}
	int ans = 0;
	for (int x = m; x <= maxx; x++) 
	{
		for (int y = m; y <= maxy; y++) 
		{
			int cnt = f[x][y] - f[x - m][y] - f[x][y - m] + f[x - m][y - m];
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}
2025/1/21 19:36
加载中...