Cod sursa(job #509374)

Utilizator vendettaSalajan Razvan vendetta Data 10 decembrie 2010 22:56:53
Problema Secventa 2 Scor 90
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.98 kb
program secv;
var
    f,g:text;
    v,s:array[0..6000000] of longint;
    k,max,sum,i,j,n,i1,i2,st:longint;
    buf:array[1..1 shl 17] of char;
begin
    assign(f,'secv2.in');reset(f);
    assign(g,'secv2.out');rewrite(g);
    settextbuf(f,buf);
    readln(f,n);
    for i:=1 to n do
        begin
            read(f,v[i]);
            s[i]:=s[i-1]+v[i];
        end;

    i1:=1;
    i2:=1;
    st:=1;
    sum:=s[1];
    max:=sum;
    for i:=2 to n do
        begin
            sum:=sum+v[i];
            if sum<s[i]-s[i-1] then
                begin
                    sum:=s[i]-s[i-1];
                    st:=i;
                end;
            if sum>max then
                begin
                    max:=sum;
                    i1:=st;
                    i2:=i;
                end;
        end;
    writeln(g,i1,' ',i2,' ',max);
    {writeln(g,i1);
    writeln(g,i2);
    for i:=i1 to i2 do write(g,v[i],' ');
    }
    close(f);
    close(g);
end.