既然正方形边上不能被消灭,那么实际的边长不是m-2吗?也就是实际一条边上有m-2个坐标才对啊?
试了很多个数据才对,但我这发ac的明显一条边有m个点啊
#include<bits/stdc++.h>
using namespace std;
int f[5005][5005]={0};int maxx=0;
int main(){
int n,m;
cin>>n>>m;
while(n--){
int x;int y;int v;
cin>>x>>y>>v;
f[x+1][y+1]+=v;
}
for(int i=1;i<=5001;i++){
for(int j=1;j<=5001;j++){
f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
}
}
for(int x=1;x<=5001;x++){
for(int y=1;y<=5001;y++){
if(x+m-1<=5001&&y+m-1<=5001){
maxx=max(-f[x+m-1][y-1]-f[x-1][y+m-1]+f[x+m-1][y+m-1]+f[x-1][y-1],maxx);
}
}
}
cout<<maxx;
return 0;
}