Cod sursa(job #301376)
var n, i, x, sum, sump:longint;
p1, p2, pp1, max, maxp:longint;
f:text;
begin
sum:=0; sump:=0;
assign (f, 'ssm.in'); reset (f);
readln (f, n);
max:= -maxlongint;
for i := 1 to n do
begin
read (f, x);
if x>max then
begin
max :=x;
maxp:=i;
end;
sump := sump+x;
if sump<0 then
begin
sump:=0;
pp1:=i+1;
end
else
begin
if sump >= sum then
begin
sum := sump;
p1:=pp1;
p2:=i;
end;
end;
end;
close (f);
if sum=0 then
begin
sum:=max;
p1:=maxp;
p2:=maxp;
end;
assign (f, 'ssm.out'); rewrite (f);
write (f, sum, ' ', p1, ' ', p2);
close (f);
end.