Cod sursa(job #1182757)
Utilizator | Data | 7 mai 2014 15:51:44 | |
---|---|---|---|
Problema | Subsecventa de suma maxima | Scor | 35 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.43 kb |
Program ssm;
var n,i,suma,pivot,aux,max,sol,k : longint;
A,lsol : array[0..6000000] of longint;
buf1,buf2 : array [0..1 shl 17] of char;
begin
assign(input,'ssm.in'); settextbuf(input,buf1); reset(input);
assign(output,'ssm.out'); settextbuf(output,buf2); rewrite(output);
readln(n);
pivot:=1;
for i:=1 to n do read(A[i]);
pivot:=1;
for i:=1 to n do begin
suma:=A[i];
pivot:=i+1;
while pivot<=n do begin
suma:=suma+A[pivot];
if suma>max then begin
max:=suma;
sol:=0;
for k:=pivot downto i do begin
sol:=sol+1;
lsol[sol]:=k;
end;
end;
pivot:=pivot+1;
end;
end;
writeln(max,' ',lsol[sol],' ',lsol[1]);
close(input);
close(output);
end.