Cod sursa(job #457309)
Utilizator | Data | 18 mai 2010 21:08:01 | |
---|---|---|---|
Problema | Secventa | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 0.5 kb |
var v,d:array[1..500010]of integer;
n,k,i,p,u,max,poz:longint;
begin
assign(input,'secventa.in');reset(input);
read(n,k);
for i:=1 to n do read(v[i]);
p:=1;
u:=0;
max:=-30002;
for i:=1 to n do begin
while (p<=u)and(v[i]<=v[d[u]]) do dec(u);
inc(u);
d[u]:=i;
if d[p]<=i-k then inc(p);
if (i>=k)and(max<v[p]) then begin
max:=v[d[p]];
poz:=i;
end;
end;
assign(output,'secventa.out'); rewrite(output);
write(poz-k+1,' ',poz,' ',max);
close(output);
end.