Cod sursa(job #123797)

Utilizator CezarMocanCezar Mocan CezarMocan Data 17 ianuarie 2008 13:30:20
Problema Teren Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.35 kb
var n,m,i,j,k,s,max,sum,q,p:longint;
    v,x:array[0..300,0..300] of longint;

begin
assign(input,'teren.in');reset(input);
assign(output,'teren.out');rewrite(output);
readln(n,m,s);
for i:=1 to n do
        for j:=1 to m do
                read(v[i,j]);
for i:=1 to m do
        for j:=1 to n do
                x[j,i]:=x[j-1,i]+v[j,i];
for i:=1 to n do
        for j:=i to n do
                begin
                //calculez arie maxima ce se poate obtine intre liniile
                //i si j
                k:=1;
                p:=0;q:=0;
                sum:=0;
                while (q<=m) do
                        begin
                        while (sum<=s)and(q<=m) do
                                begin
                                inc(q);
                                sum:=sum+x[j,q]-x[i-1,q];
                                end;
                        dec(q);
                        if (q-p)*(j-i+1)>max then
                                max:=(q-p)*(j-i+1);
                        while (sum>s)and(p<=m) do
                                begin
                                inc(p);
                                sum:=sum-(x[j,p]-x[i-1,p]);
                                end;
                        inc(q);
                        end;
                end;
writeln(max);
close(input);close(output);
end.