Cod sursa(job #1414819)

Utilizator valen.valentinValentin Valeanu valen.valentin Data 3 aprilie 2015 08:08:10
Problema Subsecventa de suma maxima Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.59 kb
program ssm;
type tabel=array[0..6000001] of longint;
     buf=array[0..1 shl 17] of char;
var t,s:tabel; ff1,ff2:buf;
    n,i,j,aux,max,ii,x:longint;
begin
assign (input,'ssm.in');
assign (output,'ssm.out');
reset (input);
rewrite (output);
settextbuf(input,ff1);
settextbuf(output,ff2);
readln (n);
for i:=1 to n do read (t[i]);
for i:=1 to n do
s[i]:=s[i-1]+t[i];
max:=-10000000; x:=0;
for i:=1 to n do begin
if s[i]-x>max then begin
max:=s[i]-x; ii:=aux+1; j:=i; end;
if s[i]<x then begin
x:=s[i]; aux:=i;
end; end;
writeln (max,' ',ii,' ',j);
close (input);
close (output);
end.