2020.12.30开始学习AcWing算法《算法竞赛进阶指南》;
上传博客方便复习。
//Wecccccccc
//2021.1.2
#include <iostream>
using namespace std;
const int N = 5010;
int mp[N][N];
int main()
{int n,m,k,r,x,y,w;cin>>k>>r;r = min(r,5001);n = m = r;while(k--){cin>>x>>y>>w;x++,y++;n = max(x,n);m = max(y,m);mp[x][y] +=w;}for (int i = 1;i<=n;i++){for (int j = 1;j<=m;j++){mp[i][j] += mp[i-1][j]+mp[i][j-1]-mp[i-1][j-1];}}int res = 0;for (int i = r;i<=n;i++){for (int j = r;j<=m;j++){res = max(res,mp[i][j]-mp[i-r][j]-mp[i][j-r]+mp[i-r][j-r]);}}cout<<res<<endl;return 0;
}