Pagini recente » Cod sursa (job #2616716) | Cod sursa (job #3235978) | Cod sursa (job #909310) | Cod sursa (job #1146719) | Cod sursa (job #55899)
Cod sursa(job #55899)
var f,g:text;
a,s:array[0..50100]of longint;
n,k,poz,x,x1,y1,y,i:longint;
sc,smax,smax1:longint;
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<0 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;
writeln(g,x,' ',y,' ',smax);
close(f);
close(g);
end.