Pagini recente » Cod sursa (job #7118) | Cod sursa (job #2788153) | Rating Costel ICHB (costel_ichb) | Cod sursa (job #977264) | Cod sursa (job #1128831)
//SSM
var a,b,c:array[1..6000001] of integer;
n,i,j,max,p1,p2:integer;
f,g:text;
begin
assign(f,'ssm.in');reset(f);
assign(g,'ssm.out');rewrite(g);
readln(f,n);
for i:=1 to n do read(f,a[i]);
close(f);
b[n]:=a[n];
c[n]:=n;
for i:=n-1 downto 1 do
if a[i]+b[i+1]<a[i] then begin
c[i]:=i;
b[i]:=a[i];
end
else begin
b[i]:=a[i]+b[i+1];
c[i]:=c[i+1];
end;
max:=-32720;
for i:=1 to n do
if b[i]>max then begin
max:=b[i];
p1:=i;
p2:=c[i];
end
else if (b[i]=max)and(c[i]-i<p2-p1)then begin
p1:=i;
p2:=c[i];
end;
write(g,max,' ',p1,' ',p2);
close(g);
end.