Pagini recente » Cod sursa (job #3240374) | Cod sursa (job #1615) | Cod sursa (job #1188537) | Cod sursa (job #430124) | Cod sursa (job #509376)
Cod sursa(job #509376)
program secv;
var
f,g:text;
v,s:array[0..6000000] of longint;
kk,k,max,sum,i,j,n,i1,i2,st:longint;
buf:array[1..1 shl 17] of char;
begin
assign(f,'secv2.in');reset(f);
assign(g,'secv2.out');rewrite(g);
settextbuf(f,buf);
readln(f,n,kk);
for i:=1 to n do
begin
read(f,v[i]);
s[i]:=s[i-1]+v[i];
end;
i1:=1;
i2:=1;
st:=1;
sum:=s[1];
max:=sum;
for i:=2 to n do
begin
sum:=sum+v[i];
if sum<s[i]-s[i-1] then
begin
sum:=s[i]-s[i-1];
st:=i;
end;
if (sum>max) and (i-st>=kk) then
begin
max:=sum;
i1:=st;
i2:=i;
end;
end;
writeln(g,i1,' ',i2,' ',max);
{writeln(g,i1);
writeln(g,i2);
for i:=i1 to i2 do write(g,v[i],' ');
}
close(f);
close(g);
end.