100分,没AC,最后一个测试点错了,很不解,有大佬帮忙解答一下吗?
#include<bits/stdc++.h>
using namespace std;
const int MAX=5e3+10;
int n,r,mp[MAX][MAX],pre_sum[MAX][MAX];
int main(){
cin>>n>>r;
int x,y,v;
for(int i=1;i<=n;i++){
cin>>x>>y>>v;
mp[x+1][y+1]=v;
}
for(int i=1;i<MAX;i++)
for(int j=1;j<MAX;j++)
pre_sum[i][j]=mp[i][j]+pre_sum[i-1][j]+pre_sum[i][j-1]-pre_sum[i-1][j-1];
int ans=0;
for(int i=r;i<MAX;i++){
for(int j=r;j<MAX;j++){
ans=max(ans,pre_sum[i][j]-pre_sum[i][j-r]-pre_sum[i-r][j]+pre_sum[i-r][j-r]);
}
}
cout<<ans<<'\n';
return 0;
}