2002 - DÃY CON CÓ TỔNG LỚN NHẤTPROGRAM SUBSEQ;CONST INP = 'SUBS...

Bài 95/2002 - Dãy con có tổng lớn nhất

Program subseq;

const inp = 'subseq.inp';

out = 'subseq.out';

var n, dau, cuoi, d:longint;

max, T:longint;

f, g:text;

Procedure input;

begin

assign(f,inp); reset(f);

assign(g,out); rewrite(g);

Readln(f,n);

End;

Procedure solve;

var i,j:longint;

dau:=1; cuoi:=1; d:=1;

max:=-maxlongint; T:=0;

for i:=1 to n do

begin

readln(f,j); T:=T + j ;

If T > max then

begin

max:=T;

dau:=d; cuoi:=i;

end;

If T<0 then begin T:=0; d:=i+1; end;

end;

Procedure output;

Begin

writeln(g,dau);

writeln(g,cuoi);

writeln(g,max);

Close(f); Close(g);

BEGIN

input;

solve;

output;

END.