Pagini recente » Cod sursa (job #1711480) | Cod sursa (job #1039715) | Cod sursa (job #2234007) | Cod sursa (job #2327533) | Cod sursa (job #700810)
Cod sursa(job #700810)
var i,j,k,n,p,p1,p2:word;
v:array[1..50000] of integer;
u:array[1..50000] of longint;
s,max1,max2,max,s1,s2:longint;
f,g:text;
begin
assign(f,'secv2.in');reset(f);
assign(g,'secv2.out');rewrite(g);
readln(f,n,k);
for i:=1 to n do
begin
read(f,v[i]);
if i<=k then s:=s+v[i];
end;
u[k]:=s;
max:=u[k];
p:=k;
for i:=k+1 to n do
begin
s:=s-v[i-k]+v[i];
u[i]:=s;
if u[i]>max then begin
max:=u[i];
p:=i;
end;
end;
max1:=0;
max2:=0;
s1:=0;
s2:=0;
for i:=p-k downto 1 do
begin
s1:=v[i]+s1;
if s1>max1 then begin
max1:=s1;
p1:=i;
end;
end;
for i:=p+1 to n do
begin
s2:=s2+v[i];
if s2>max2 then begin
max2:=s2;
p2:=i;
end;
end;
if max1>0 then max:=max+max1
else p1:=p-k+1;
if max2>0 then max:=max+max2
else p2:=p;
write(g,p1,' ',p2,' ',max);
close(f);
close(g);
end.