e-olymp
Задачи

Черепашка

опубликовано 05.11.2020, 08:21:24

var n, m:integer; a, b:array[1..1000, 1..1000]of longint; procedure form; var i, j:integer; begin for i:=1 to n do for j:=1 to m do read(a[i, j]); end; procedure formB; var i, j:integer; begin b[1, 1]:=a[1, 1]; for i:=2 to m do b[1, i]:=(b[1, i-1]+a[1, i]); for i:=2 to n do b[i, 1]:=(b[i-1, 1]+a[i, 1]); for i:=2 to n do for j:=2 to m do if b[i-1, j]<b[i, j-1] then b[i, j]:=(b[i-1, j]+a[i, j]) else b[i, j]:=(b[i, j-1]+a[i, j]); end; begin readln(n, m); form; formB; write(b[n, m]); end.