Cod sursa(job #18621)

Utilizator Darth_NiculusIvan Nicolae Darth_Niculus Data 18 februarie 2007 12:48:24
Problema Plantatie Scor 20
Compilator cpp Status done
Runda preONI 2007, Runda 2, Clasa a 10-a Marime 1 kb
#include <stdio.h>

#define NMAX 600
#define MMAX 76000

int i,j,n,m,A[NMAX][NMAX],MP[NMAX][NMAX],k;

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",&A[i][j]);

 MP[0][0]=A[1][1];
 for (i=1;i<=n;i++)
 for (j=1;j<=n;j++)
    {
     if (MP[i-1][j-1] > MP[i][j])
       MP[i][j]=MP[i-1][j-1];
     for (k=1;k<=i;k++)
        if (A[k][j] > MP[i][j])
          MP[i][j]=A[k][j];
     for (k=1;k<=j;k++)
        if (A[i][k] > MP[i][j])
          MP[i][j]=A[i][k];
    }

 for (k=1;k<=m;k++)
    {
     int x,y,l;
     scanf("%d%d%d",&x,&y,&l);

     if (MP[i+l-1][j+l-1] > MP[i+l-1][j-1] && MP[i+l-1][j+l-1] > MP[i-1][j+l-1])
       printf("%d\n",MP[i+l-1][j+l-1]);
       else
     {
      int max=0;
      for (i=x;i<=x+l-1;i++)
      for (j=y;j<=y+l-1;j++)
         if (A[i][j]>max)
           max=A[i][j];
          
      printf("%d\n",max);
     }
    }

 fclose(stdin);
 fclose(stdout);
 
 return 0;
}