Skip to content

Instantly share code, notes, and snippets.

@ileasile
Created January 13, 2020 01:18
Show Gist options
  • Save ileasile/9a22305f811a9a8f463b2e7b2b2ea537 to your computer and use it in GitHub Desktop.
Save ileasile/9a22305f811a9a8f463b2e7b2b2ea537 to your computer and use it in GitHub Desktop.
procedure maxi(var a: integer; b: integer);
begin
if a < b then
a := b
end;
begin
var b, c: array [0..1999] of shortint;
var r, n, x, bj, bp, ap, app, s1, s2: integer;
ReadLn(n);
r := -310;
n := n - 1;
for var i := 0 to n do
begin
var s := System.Console.ReadLine;
var nextInd := 1;
for var j := 0 to n do
begin
x := s.ReadInteger(nextInd);
bp := bj;
bj := b[j];
s1 := x + ap;
s2 := x + bj;
if i > 0 then
begin
if j > 0 then
begin
maxi(r, s1 + max(bj, bp));
maxi(r, s2 + bp);
end;
if j < n then
maxi(r, s2 + b[j + 1]);
if i > 1 then
maxi(r, s2 + c[j]);
end;
if j > 1 then
begin
maxi(r, s1 + app);
end;
app := ap;
ap := x;
c[j] := bj;
b[j] := x;
end;
if i mod 9 = 0 then
System.GC.Collect;
end;
Write(r);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment