Cod sursa(job #593716)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 4 iunie 2011 12:23:06
Problema Secventa Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.47 kb
var a,d:array[1..500000] of integer;
    n,k,i,p,u,max,x,y,t:longint;
begin
assign(input,'secventa.in');reset(input);
assign(output,'secventa.out');rewrite(output);
readln(n,k);
for i:=1 to n do read(a[i]);
p:=1;u:=0;max:=-maxint;
for i:=1 to n do
begin
while (p<=u) and (a[i]<a[d[u]]) do dec(u);
inc(u);
d[u]:=i;
if i-d[p]=k then inc(p);
if (i>=k) and (a[d[p]]>max) then
begin
max:=a[d[p]];
t:=i;
end;
end;
writeln(t-k+1,' ',t,' ',max);
close(output);
end.