【NOIP04普及组】花生采摘 谁会
发布网友
发布时间:2024-10-07 21:12
我来回答
共1个回答
热心网友
时间:2024-12-04 19:58
var
p:array[1..20,1..20] of longint;
n,m,k,t,i,j,ans,max,maxli,maxlj,maxi,maxj:longint;
begin
readln(m,n,k);
for i:=1 to m do
for j:=1 to n do
read(p[i,j]);
k:=k-2;
t:=0;
ans:=0;
max:=0;
for i:=1 to m do
for j:=1 to n do
if p[i,j]>max then
begin
max:=p[i,j];
maxi:=i;
maxj:=j;
end;
t:=t+maxi;
while (t+maxi-1<=k)and(max>0) do
begin
ans:=ans+max;
p[maxi,maxj]:=0;
max:=0;
for i:=1 to m do
for j:=1 to n do
if p[i,j]>max then
begin
max:=p[i,j];
maxli:=i;
maxlj:=j;
end;
t:=t+1+abs(maxli-maxi)+abs(maxlj-maxj);
maxi:=maxli;
maxj:=maxlj;
end;
writeln(ans);
end.