Cod sursa(job #65105)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 7 iunie 2007 08:09:36
Problema Subsir 2 Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.59 kb
var a,b:array[1..5000] of longint;
min,n,i,j,k,l,max,poz:longint;
begin
assign(input,'subsir2.in');
assign(output,'subsir2.out');
reset(input);
reset(output);
readln(n);
for i:=1 to n do read(a[i]);
for i:=n-1 downto 1 do
        begin
        max:=0;
        for j:=i+1 to n do
                if (a[i]<a[j])and(max<b[j]) then max:=b[j];
        end;
max:=0;
for i:=1 to n do
        if b[i]>max then max:=b[i];
writeln(max);
poz:=1;
repeat
min:=maxlongint;
for i:=poz to n do
if (b[i]=max)and(a[i]<min) then
        poz:=i;
write(a[i],' ');
dec(max);
until max=0;
close(input);
close(output);
end.