Pagini recente » Cod sursa (job #3162147) | Cod sursa (job #1730223) | Cod sursa (job #1173352) | Cod sursa (job #2216976) | Cod sursa (job #28802)
Cod sursa(job #28802)
var n,k,max,maxi,maxj,i:longint;
a:array[1..50000]of integer;
p,s:array[1..50000]of longint;
f,g:text;
begin
assign(f,'secv2.in');
reset(f);
readln(f,n,k);
read(f,a[1]);
p[1]:=a[1];
s[1]:=1;
max:=-maxint;
maxi:=1;
maxj:=1;
if k=1 then max:=a[1];
for i:=2 to n do begin
read(f,a[i]);
if p[i-1]>0 then begin
p[i]:=p[i-1]+a[i];
s[i]:=s[i-1];
end
else begin
p[i]:=a[i];
s[i]:=i;
end;
if p[i]>max then if i-s[i]+2>k then begin
max:=p[i];
maxi:=s[i];
maxj:=i;
end;
end;
assign(g,'secv2.out');
rewrite(g);
write(g,maxi,' ',maxj,' ',max);
close(g);
end.