源代码: var t,m,n,k,i,j:longint; max,max1,max2,max3,max4,total:longint; a:array[1..20,1..20] of longint; begin readln(m,n,k); k:=k-2; max:=0; for i:=1to m do for j:=1to n do begin read(a[i,j]); if a[i,j]>max thenbegin max:=a[i,j]; max1:=i; max2:=j; end; end; t:=max1;total:=0; while (t+max1-1<=k) and (max>0) do begin a[max1,max2]:=0;total:=total+max; max:=0; for i:=1to m do for j:=1to n do if a[i,j]>max thenbegin max:=a[i,j]; max3:=i; max4:=j; end; t:=t+1+abs(max1-max3)+abs(max2-max4); max1:=max3;max2:=max4; end; writeln(total); end.