HELPPM - Giúp ngài thủ tướng!
Tác giả: flashmt
Ngôn ngữ: Pascal
const fi='';
fo='';
maxn=501;
maxc=100000000;
var n,m,i,j,re,h,w,t,x,y,k:longint;
a:array[1..maxn,0..maxn] of longint;
procedure pr;
var i,l,r,min,s,f,hx,sum:longint;
begin
re:=maxc;
for i:=1 to n do
for l:=1 to n-i+1 do
begin
if i>re then break;
r:=l+i-1; min:=maxlongint; hx:=0;
s:=1; f:=1;
sum:=a[1,r]-a[1,l-1];
while (s<=f) and (f<=m) do
begin
if sum<k then
begin
f:=f+1;
sum:=sum+a[f,r]-a[f,l-1];
end
else
begin
if f-s+1<min then
begin
min:=f-s+1;
hx:=s;
end;
sum:=sum-a[s,r]+a[s,l-1];
s:=s+1;
end;
end;
if min=maxlongint then continue;
if (min*i<re) then
begin
re:=min*i;
h:=min; w:=i; x:=hx; y:=l;
end;
end;
end;
procedure wf;
begin
assign(output,fo);
rewrite(output);
if re<maxc then
begin
writeln(re);
write(x,' ',y,' ',x+h-1,' ',y+w-1);
end
else write(-1);
close(output);
end;
begin
assign(input,fi);
reset(input);
read(m,n,k);
for i:=1 to m do
for j:=1 to n do
begin
read(t);
a[i,j]:=a[i,j-1]+t;
end;
close(Input);
pr;
wf;
end.