Pagini recente » Cod sursa (job #1148647) | Cod sursa (job #1604422) | Cod sursa (job #1625501) | Cod sursa (job #2800139) | Cod sursa (job #947207)
Cod sursa(job #947207)
program subsecventa_de_suma_maxima;
var a:array[1..6000000]of longint;
buf:array[1..100000]of byte;
n,i,min,max,pozmax,smax,l,r,pozmin:longint;
begin
assign(input,'ssm.in');
reset(input);
settextbuf(input,buf);
assign(output,'ssm.out');
rewrite(output);
readln(n);
read(a[1]);max:=a[1];pozmax:=1;smax:=a[1];l:=1;r:=1;
for i:=2 to n do
begin
read(a[i]);
if a[i]>max then begin max:=a[i];pozmax:=i;end;
a[i]:=a[i]+a[i-1];
if a[i]<min then begin min:=a[i]; pozmin:=i; end;
if a[i]-min>smax then begin smax:=a[i]-min; l:=pozmin+1;r:=i;end;
end;
if smax=0 then writeln(max,' ',pozmax,' ',pozmax) else writeln(smax,' ',l,' ',r);
close(input);close(output);
end.