Untitled

mail@pastecode.io avatar
unknown
pascal
2 years ago
676 B
18
Indexable
Never
uses math;
var f1,f2:text;
    i,n:longint;
    a:array[1..1000000] of longint;
    F:array[0..1000000] of int64;
procedure Enter;
begin
        assign(f1,'candy.inp');
        reset(f1);
        readln(f1,n);
        for i:=1 to n do read(f1,a[i]);
        close(f1);
end;
procedure Solve;
begin
        F[0]:=0;
        F[1]:=a[1];
        F[2]:=a[1]+a[2];
        for i:=3 to n do
                F[i]:=max(F[i-1], max(F[i-2]+a[i],F[i-3]+a[i-1]+a[i]));
end;
procedure Result;
begin
        assign(f2,'candy.out');
        rewrite(f2);
        write(f2,F[n]);
        close(f2);
end;
begin
        Enter;
        Solve;
        Result;
end.