Pagini recente » Cod sursa (job #879946) | Cod sursa (job #2013070) | Cod sursa (job #2149484) | Cod sursa (job #434232) | Cod sursa (job #603806)
Cod sursa(job #603806)
Program secventa;
var i,j,k,posmin,inceput,sfirsit,n,max,min:longint;
a: array [1..500000] of integer;
b1,b2: array [1..1 shl 17] of char;
fi,fo:text;
begin
assign(fi,'secventa.in');
assign(fo,'secventa.out');
settextbuf(fi,b1);
settextbuf(fo,b2);
reset(fi);
rewrite(fo);
readln(fi,n,k);
for i:=1 to n do read(fi,a[i]);
min:=a[1];
for i:=2 to k do
if a[i]<=min then begin
min:=a[i];
posmin:=i;
end;
max:=min; inceput:=1; sfirsit:=k;
for i:=2 to n-k+1 do begin
if i<=posmin then
if a[i+k-1]<=min then begin
min:=a[i+k-1];
posmin:=i+k-1;
end;
if i>posmin then begin
min:=a[i];
for j:=i+1 to i+k-1 do
if a[j]<=min then begin
min:=a[j];
posmin:=j;
end
else posmin:=i;
end;
if min>max then begin
inceput:=i;
sfirsit:=i+k-1;
max:=min;
end;
end;
write(fo,inceput,' ',sfirsit,' ',max);
close(fo);
end.