2 1
0 0 1
1 1 1
输入
1
这道题就是最基础的二位前缀和的应用,如果不会的话可以点击下方链接学习哟
前缀和差分详解
#include<iostream>
#include<stdio.h>
//#include<string.h>
#include<algorithm>
//#include<queue>
//#define ls (p<<1)
//#define rs (p<<1|1)
//#define mid (l+r)/2
#define over(i,s,t) for(int i=s;i<=t;++i)
#define lver(i,t,s) for(int i=t;i>=s;--i)
using namespace std;
typedef int ll;//long long 比较占用内存,如果MLE了可能是long long 的锅!!!!!!!!!!
const ll N=5007;
//const ll INF=1e13+7;
//const ll mod=2147483647;
//const double EPS=1e-6;
ll n,m;
ll b[N][N];
ll x,y,v,ans;
int main()
{
scanf("%d%d",&n,&m);
over(i,1,n)
scanf("%d%d%d",&x,&y,&v),b[x+1][y+1]=v;
over(i,1,5001)over(j,1,5001)
b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+b[i][j];
over(i,0,5000-m)over(j,0,5000-m)
ans=max(ans,b[i+m][j+m]-b[i+m][j]-b[i][j+m]+b[i][j]);
printf("%d\n",ans);
return 0;
}
有任何疑问欢迎评论哦虽然我真的很菜