机器清洁工

矩阵前缀和模板题。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <cctype>
#include <queue>
#include <ctime>
#include <vector>
using namespace std;
const int n=1025;
const int Max=1100;
int d,s,maxx,ans;
int num[Max][Max],sum[Max][Max];

inline int get_int()
{
int x=0,f=1;
char c;
for(c=getchar();(!isdigit(c))&&(c!='-');c=getchar());
if(c=='-') {f=-1;c=getchar();}
for(;isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+c-'0';
return x*f;
}

int main()
{
//freopen("cleaner.in","r",stdin);
//freopen("cleaner.out","w",stdout);

d=get_int();
s=get_int();
for(register int i=1;i<=s;i++)
{
int x=get_int(),y=get_int(),z=get_int();
num[x][y]=z;
}

for(register int i=0;i<=n;i++)
for(register int j=0;j<=n;j++)
sum[i][j]=num[i][j]+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];

for(register int i=2*d;i<=n;i++)
for(register int j=2*d;j<=n;j++)
maxx=max(sum[i][j]-sum[i-2*d-1][j]-sum[i][j-2*d-1]+sum[i-2*d-1][j-2*d-1],maxx);

for(register int i=2*d;i<=n;i++)
for(register int j=2*d;j<=n;j++)
if(maxx==sum[i][j]-sum[i-2*d-1][j]-sum[i][j-2*d-1]+sum[i-2*d-1][j-2*d-1]) ans++;

cout<<ans<<" "<<maxx<<"\n";
return 0;
}