Pagini recente » Cod sursa (job #335078) | Cod sursa (job #1465182) | Cod sursa (job #3279939) | Cod sursa (job #1175530) | Cod sursa (job #55889)
Cod sursa(job #55889)
var f,g:text;
a,s:array[0..50100]of int64;
n,k,poz,x,x1,y1,y,i:longint;
sc,smax,smax1:int64;
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,a[i]);
s[i]:=s[i-1]+a[i];
end;
sc:=s[k];poz:=1;
smax:=s[k];x:=1;y:=k;
for i:=k to n do
begin
if sc<s[i]-s[i-k] then begin
sc:=s[i]-s[i-k];
poz:=i-k+1;
end
else sc:=sc+a[i];
if sc>smax then if i-poz+1>=k then begin
smax:=sc;
x:=poz;
y:=i;
end;
end;}
sc:=a[1];poz:=1;
smax1:=a[1];x1:=1;y1:=1;
for i:=2 to n do
begin
if sc<0 then begin
sc:=a[i];
poz:=i;
end
else sc:=sc+a[i];
if sc>smax1 then if i-poz+1>=k then begin
smax1:=sc;
x1:=poz;
y1:=i;
end;
end;
{if smax>smax1 then writeln(g,x,' ',y,' ',smax)
else if y1-x1+1>=k then} writeln(g,x1,' ',y1,' ',smax1);
close(f);
close(g);
end.