Cod sursa(job #593708)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 4 iunie 2011 12:15:54
Problema Secventa Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.56 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:=d[p];
end;
end;
x:=t+1;
y:=t+1;
while (a[x]>=a[t]) and (x>=1) do dec(x);
while (a[y]>=a[t]) and (y<=n) do inc(y);
writeln(x+1,' ',y-1,' ',max);
end.