Cod sursa(job #418937)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 16 martie 2010 18:56:11
Problema Teren Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <stdio.h>
#define DIM 301

int v[DIM][DIM];

int n,m,b,max,s;
int i,j,p,u,x;

int main(){
	
	FILE *f1 = fopen("teren.in","r");
	FILE *f2 = fopen("teren.out","w");
	
	fscanf(f1,"%d%d%d",&n,&m,&b);
	
	for(i=1; i<=n; i++)
		for(j=1; j<=m; j++){
			fscanf(f1,"%d",&x);
			v[i][j] = v[i-1][j] + x;
		}

	for(i=1; i<=n; i++)
		for(j=i; j<=n; j++){
			
			p = 1;
			s = 0;
			
			for(u=1; u<=m; u++){
				
				s += v[j][u] - v[i-1][u]; 
				
				while(s > b){
					s -= v[j][p] - v[i-1][p];
					p++;					
				}				
				
				if((u-p+1)*(j-i+1) > max)
					max = (u-p+1)*(j-i+1) ;				
			}
		}	
	
	fprintf(f2,"%d",max);	
	
	fclose(f1);
	fclose(f2);
	
	return 0;
}