Pagini recente » Cod sursa (job #658287) | Cod sursa (job #1105904) | Cod sursa (job #3249611) | Cod sursa (job #115634) | Cod sursa (job #570118)
Cod sursa(job #570118)
var a,b:array[0..6000000] of longint;
v:array[1..3,1..6000000] of longint;
buf:array[1..100000000] of char;
n,i,j,k,poz,p,s,x,y:longint;
sir:string;
f,g:text;
begin
assign(f,'ssm.in');
assign(g,'ssm.out');
reset(f);
settextbuf(f,buf);
rewrite(g);
readln(f,n);
poz:=1;
p:=1;
while not eoln(f) do
begin
read(f,sir);
for j:=1 to length(sir) do
begin
if sir[j]=' ' then begin a[poz]:=a[poz]*p; inc(poz); p:=1; end else
if sir[j]='-' then p:=-1 else
begin
a[poz]:=a[poz]*10 + ord(sir[j])-ord('0');
end;
end;
end;
a[poz]:=a[poz]*p;
for i:=1 to n do
begin
//read(f,a[i]);
b[i]:=b[i-1]+a[i];
end;
s:=-10000000;
for i:=1 to n do
begin
for j:=0 to i-1 do
if b[i]-b[j]>s then
begin
s:=b[i]-b[j];
x:=j+1;
y:=i;
end else
if b[i]-b[j]=s then
if i-j<y-x then
begin
x:=j+1;
y:=i;
end;
end;
{ i:=1;
poz:=1;
while a[i]<=0 do inc(i);
s:=0;
s3:=0;
t:=i;
while i<=n do
begin
j:=i;
s1:=0;
while a[j]>0 do
begin
s1:=s1+a[j];
inc(j);
end;
k:=j;
s2:=0;
while a[k]<0 do
begin
s2:=s2+a[k];
inc(k);
end;
if s2<0 then begin
if s1+s2>=0 then
begin
s3:=s3+s1+s2;
i:=k;
end else
begin
s3:=s3+s1;
if s3>s then
begin
s:=s3;
x:=t;
y:=j-1;
end;
t:=k;
i:=k;
s3:=0;
end; end else
begin
s3:=s3+s1;
if s3>s then
begin
s:=s3;
x:=t;
y:=j-1;
end;
t:=k;
i:=k;
s3:=0;
end;
end;}
write(g,s,' ',x,' ',y);
close(g);
end.