Cod sursa(job #298920)

Utilizator andreivFMI - vacaroiu andrei andreiv Data 6 aprilie 2009 14:36:25
Problema Teren Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <stdio.h>
#include <string.h>
int c[305][305];
int main()
{long int st,dr,i,j,l1,l2,n,m,s,x,max=0;

freopen("teren.in","r",stdin);
freopen("teren.out","w",stdout);
 
scanf("%ld %ld %ld",&n,&m,&x);
for (i=1;i<=m;i++) c[0][i]=0;

 
 for (i=1;i<=n;i++)
	for (j=1;j<=m;j++)
	{scanf("%ld",&s);c[i][j]=c[i-1][j]+s;}
	
 for (l1=1;l1<n;l1++)
    for (l2=l1;l2<=n;l2++)
	{st=1;s=0;
	 for (dr=1;dr<=m;dr++)
	   {s+=c[l2][dr]-c[l1-1][dr];
		for (;((s>x)&&(st<=dr)); st++)
		  s-=(c[l2][st]-c[l1-1][st]);
		if ((st<=dr) && ((dr-st+1)*(l2-l1+1)>max))
		 max=(dr-st+1)*(l2-l1+1);// printf("l1%ld c1%ld l2%ld c2%ld max%ld",l1,st,l2,dr,max);}
	   }
	}	
printf("%ld\n",max); 	
 
 
 
 
 return 0;}