Pagini recente » Monitorul de evaluare | Cod sursa (job #1711799) | Cod sursa (job #192618) | Cod sursa (job #616278) | Cod sursa (job #743331)
Cod sursa(job #743331)
Program p1;
var fi,fo : text;
i,n,j1,j2,max : longint;
a,c:array[0..600005] of longint;
begin
assign(fi,'ssm.in'); reset(fi); readln(fi,n);
assign(fo,'ssm.out'); rewrite(fo);
read(fi,a[1]); max:=a[1]; j1:=1; j2:=1; c[1]:=a[1];
for i:=2 to n do begin
read(fi,a[i]);
if c[i-1]+a[i]>=a[i] then c[i]:=c[i-1]+a[i]
else c[i]:=a[i];
if c[i]>max then begin max:=c[i]; j2:=i; end;
end;
j1:=j2;
write(fo,max,' ');
while max<>0 do begin
max:=max-a[j1];
j1:=j1-1;
end;
if a[j1]<>0 then j1:=j1+1;
if j1>j2 then j1:=j2;
write(fo,j1,' ',j2);
close(fi); close(fo);
end.