Pagini recente » Cod sursa (job #573957) | Cod sursa (job #1864379) | Cod sursa (job #2477399) | Cod sursa (job #2413229) | Cod sursa (job #55881)
Cod sursa(job #55881)
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:=s[k];poz:=1;
smax1:=s[k];x1:=1;y1:=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>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.