Cod sursa(job #285069)

Utilizator b_ady20Branescu Adrian b_ady20 Data 22 martie 2009 12:41:18
Problema Secventa Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.96 kb
const n=500*1001;
      m=n*7;
var x,y,i,j,k,p,ln,u:integer;
        max:longint;
                a,d:array[1..n] of integer;
                s:array[1..m] of char;
procedure cif;
var i,j,c:integer;
begin
i:=0;
while not eoln(input) do
begin
inc(i);
read (input,s[i]);
end;
j:=1;
for i:=1 to ln do
begin
while s[j]=' ' do
inc (j);
if s[j]='-' then begin
c:=1; inc (j);   end
else c:=0;
while (s[j]>='0')and(s[j]<='9')do
begin
a[i]:=a[i]*10+ord(s[j])-48;
inc(j);
end;
if c=1 then
a[i]:=a[i]*(-1);
end;
end;
begin
max:=-100000;
assign (input,'secventa.in');
reset (input);
readln (input,ln,k);
cif;
p:=1; u:=0;
for i:=1 to ln do
begin
while (p<=u) and (a[i]<=a[d[u]]) do
dec (u);
inc (u);
d[u]:=i;
if d[p]=i-k then
inc (p);
if i>=k then
if a[d[p]]>max then
begin
max:=a[d[p]];
x:=i-k+1;
y:=i;
end;
end;
close (input);
assign (output,'secventa.out');
rewrite (output);
write (output,x,' ',y,' ',max);
close (output);
end.