Pagini recente » Cod sursa (job #478704) | Cod sursa (job #2776767) | Cod sursa (job #2946319) | Cod sursa (job #2092907) | Cod sursa (job #29722)
Cod sursa(job #29722)
var a,b:array[1..50000] of Integer; SM,SC,ince,sf,poz,i,n,min,nr,j,k:longint; f1,f2:text;
Begin
assign(f1,'secv2.in');
reset(f1);
assign(f2,'secv2.out');
rewrite(f2);
read(f1,n,k);
for i:=1 to n do read(f1,a[i]);
SM:=a[1];
SC:=SM;
poz:=1;
ince:=1;
sf:=1;
min:=-maxint;
for i:=2 to n do
begin
if SC<0 then
begin
SC:=a[i];
poz:=i
end
else SC:=SC+a[i];
if i-poz+1>k then if Sm<SC then
begin
SM:=SC;
ince:=poz;
sf:=i;
end;
end;
for j:=ince to sf do b[j]:=1;
nr:=nr-(sf-ince+1);
write(f2,POZ,' ',SF,' ',sm);
close(f1);
close(f2);
End.