Pagini recente » Cod sursa (job #122006) | Cod sursa (job #110173) | Cod sursa (job #544792) | Cod sursa (job #492483) | Cod sursa (job #29729)
Cod sursa(job #29729)
var a,b:array[1..50000] of Integer; SM,SC,ince,sf,poz,i,n,min,nr,j,k,s: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 begin read(f1,a[i]); s:=s+a[i]; end;
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;
if n=k then begin sf:=n; sm:=s; end;
write(f2,ince,' ',SF,' ',sm);
close(f1);
close(f2);
End.