Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type
- TArray = array[1..1000, 1..1000] of Longint;
- TTArray = array[1..1000] of longint;
- var
- i, j, n, m, max, x1, x2, y1, y2, nnn: longint;
- a, b, c: TArray;
- xx,yy: TTArray;
- procedure rec(i, j: Longint; b: TArray; sum: Longint; x,y: TTArray; nn:longint);
- begin
- if (i < 1) or (i > n) or (j < 1) or (j > m) then exit;
- if c[i, j] = 1 then exit;
- if b[i, j] = 2 then
- begin
- c[i, j] := 1;
- exit;
- end;
- inc(b[i, j]);
- sum := sum +a[i, j];
- inc(nn);
- x[nn] := i;
- y[nn] := j;
- if (i = x2) and (j = y2) then
- if sum > max then
- begin
- max := sum;
- xx := x;
- yy := y;
- nnn := nn;
- exit;
- end;
- rec(i + 1, j, b, sum, x, y, nn);
- rec(i - 1, j, b, sum, x, y, nn);
- rec(i, j + 1, b, sum, x, y, nn);
- rec(i, j - 1, b, sum, x, y, nn);
- end;
- begin
- readln(n, m);
- for i := 1 to n do
- for j := 1 to m do
- read(a[i,j]);
- readln(x1, y1);
- readln(x2, y2);
- rec(x1, y1, b, 0, xx, yy, 0);
- writeln(max);
- for i := 1 to nnn do
- writeln(xx[i], ' ', yy[i]);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement