Chotkos / 7 lat, 9 miesięcy temu | Download | Plaintext | Odpowiedz |

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var
a,b:array[0..1001,0..1001] of longint;
m,n,l,i:longint;


begin
readln(n,m);
for i:=1 to n do
begin
        for l:=1 to m do
        begin
                read(a[i,l]);
        end;
end;

i:=1; l:=i;
b[i,l]:=a[i,l];

for l:=0 to m+1 do a[0,l]:=-1000001;

for l:=0 to m+1 do a[n+1,l]:=-1000001;

for i:=0 to n+1 do
begin
        a[i,0]:=-1000001;
        a[i,m+1]:=-1000001;
end;


for i:=1 to n do
begin
        for l:=1 to m do
        begin


                if (b[i-1,l] > b[i,l-1]) then
                b[i,l]:=a[i,l]+b[i-1,l]  else
                b[i,l]:=a[i,l]+b[i,l-1];

                if a[i,l]=0 then b[i,l]:=0;
        end;
end;

writeln(b[m,n]);
end.