Last active
January 12, 2020 04:53
-
-
Save ileasile/20fcf5772d43452acf78c74bc98d75e3 to your computer and use it in GitHub Desktop.
Maximal triple task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var | |
b, c: array [0..1999] of shortint; | |
r, n, s, i, j, x, bj, bp, ap, app: integer; | |
function max(a, b: integer): integer; | |
begin | |
if a > b then | |
max := a | |
else | |
max := b; | |
end; | |
procedure maxi(var a: integer; b: integer); | |
begin | |
if a < b then | |
a := b | |
end; | |
begin | |
Read(n); | |
r := -310; | |
n := n - 1; | |
for i := 0 to n do | |
for j := 0 to n do | |
begin | |
Read(x); | |
bp := bj; | |
bj := b[j]; | |
if i > 0 then | |
begin | |
if j > 0 then | |
begin | |
s := x + ap; | |
maxi(r, s + max(bj, bp)); | |
maxi(r, x + bj + bp); | |
end; | |
if j < n then | |
maxi(r, x + bj + b[j + 1]); | |
if i > 1 then | |
maxi(r, x + bj + c[j]); | |
end; | |
if j > 1 then | |
begin | |
maxi(r, x + ap + app); | |
end; | |
app := ap; | |
ap := x; | |
c[j] := bj; | |
b[j] := x; | |
end; | |
Write(r); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment