求条 91pts
查看原帖
求条 91pts
1415788
absolutevalue_y楼主2024/12/3 19:34
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[5005][5005];
int s[5005][5005];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n,r;
	cin>>n>>r;
	for(int i=1; i<=n; i++){
		int x,y,w; 
		cin>>x>>y>>w;
		a[x][y]=w;
	}
	for(int i=1; i<=5000; i++){
		for(int j=1; j<=5000; j++){
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
		}
	}
	int maxn=LLONG_MIN;
	for(int i=1; i<=5000-r+1; i++){
		for(int j=1; j<=5000-r+1; j++){
			int x1=i-1,yy1=j-1,x2=i+r-1,yy2=j+r-1;
			if(x1<0) x1=0; if(yy1<0) yy1=0; if(x2>5000) x2=5000; if(yy2>5000) yy2=5000;
			maxn=max(maxn,s[x2][yy2]-s[x2][yy1]-s[x1][yy2]+s[x1][yy1]);
		}
	}
	cout<<maxn<<"\n";
	return 0;
}
2024/12/3 19:34
加载中...