Pagini recente » Cod sursa (job #2447267) | Cod sursa (job #139821) | Cod sursa (job #3279205) | Cod sursa (job #2762309) | Cod sursa (job #1450364)
#include <stdio.h>
#define inf 0x3f3f3f3f
#define nmax 100010
using namespace std;
int n,m,i,j,k,x,y,z,dp[502][502][502];
inline int max(int a,int b)
{
if (a>b) return a; else return b;
}
int main(){
freopen("plantatie.in","r",stdin);
freopen("plantatie.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
scanf("%d",&dp[1][i][j]);
for (k=2;k<=n;k++){
for (i=1;i<=n-k+1;i++)
for (j=1;j<=n-k+1;j++)
dp[k][i][j]=max(dp[k-1][i][j],max(dp[k-1][i+1][j],max(dp[k-1][i][j+1],dp[k-1][i+1][j+1])));
}
for (i=1;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
printf("%d\n",dp[z][x][y]);
}
return 0;
}