blob: fa568dc6d5fb0379b119eb18e7121e801d09fdf6 (
plain) (
blame)
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
|
var
n, m, i, j: int16;
a: array of array of int32;
s: int64 = 0;
begin
readln(n, m);
setlength(a, n + 2);
setlength(a[0], m + 2);
for i := 0 to m + 1 do
a[0][i] := 0;
for i := 1 to n do
begin
setlength(a[i], m + 2);
a[i][0] := 0;
for j := 1 to m do
read(a[i][j]);
a[i][m + 1] := 0
end;
setlength(a[n + 1], m + 2);
for i := 0 to m + 1 do
a[n + 1][i] := 0;
for i := 1 to n do
for j := 1 to m do
if a[i][j] <> 0 then
begin
if a[i][j] > a[i - 1][j] then
s := s + a[i][j] - a[i - 1][j];
if a[i][j] > a[i + 1][j] then
s := s + a[i][j] - a[i + 1][j];
if a[i][j] > a[i][j - 1] then
s := s + a[i][j] - a[i][j - 1];
if a[i][j] > a[i][j + 1] then
s := s + a[i][j] - a[i][j + 1];
s := s + 1
end;
writeln(s)
end.
|