Skip to content

Instantly share code, notes, and snippets.

@swapnil-warke
Created June 15, 2013 17:52
Show Gist options
  • Save swapnil-warke/5788943 to your computer and use it in GitHub Desktop.
Save swapnil-warke/5788943 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<limits>
using namespace std;
int dp[1024+3][1024+3];
int main()
{
int t,n,x,y,p,d;
cin>>t;
while(t--)
{
cin>>d;
cin>>n;
for(int i=0;i<=1025;i++)
for(int j=0;j<=1025;j++)
dp[i][j]=0;
for(int i=0;i<n;i++)
{
cin>>x>>y>>p;
dp[x][y]=p;
}
//preproccessing
for(int i=1;i<=1025;i++)
for(int j=1;j<=1025;j++)
dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+dp[i][j];
int mx=numeric_limits<int>::min();
int mxx=0;
int mxy=0;
for(int i=d+1;i<=1025-d;i++)
for(int j=d+1;j<=1025-d;j++)
{
int temp=dp[i+d][j+d]-dp[i+d][j-d-1]-dp[i-d-1][j+d]+dp[i-d-1][j-d-1];
if(mx<temp)
{
mx=temp;
mxx=i;
mxy=j;
}
}
cout<<mxx<<" "<<mxy<<" "<<mx<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment